SiteMaze Posted January 2, 2008 Share Posted January 2, 2008 Hello, How to do a multikey sort of a 2d array? I want to sort a CSV file, so I read the file to a 2d array. Then I want to do a mutikey sort, first sort by column A, then by column B. I have search the forum and all it came up is one level sort. Thanks in advance. Arsenal Football Fan Club in Singapore Link to comment Share on other sites More sharing options...
weaponx Posted January 2, 2008 Share Posted January 2, 2008 (edited) This didn't work for you? #include <Array.au3> Dim $array[4][2] $array[0][0] = "A" $array[0][1] = "Z" $array[1][0] = "B" $array[1][1] = "A" $array[2][0] = "C" $array[2][1] = "A" $array[3][0] = "A" $array[3][1] = "B" ;_ArrayDisplay($array) _ArraySort($array, 0,0,0,2,0) _ArrayDisplay($array) Edited January 2, 2008 by weaponx Link to comment Share on other sites More sharing options...
randallc Posted January 2, 2008 Share Posted January 2, 2008 (edited) Hi, (btw @ WeaponX, that sort only sort sequentialy on one column at a time, I think, not on subsorts for matching rows?) See the link in my signature for Attay2D; I think the zip file wih examples is still there too. PM me if an problems; it is aalso udes to show it is woking in the script SearchMIner in the display; it has to be converted to ArrayOfStrings by the fnction first; I had it in "Au3" pure if you can't use vbs for any reason, but it was slow on large sorts. best Randall $i_ColSortIndex = "2|-5|3";,[numbered by base 1 (ie first col number is "1")] [Sorts on cols 2,4,3 {DESC on 4 as NEGATIVE}] ;=============================================================================== $timerstamp3 = TimerInit() _Array2D1DFieldSortSt($ar_TempSingle, $i_ColSortIndex);_Array2D1DFieldSortSt [or serach forum on "subsort"] Edited January 2, 2008 by randallc ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
weaponx Posted January 2, 2008 Share Posted January 2, 2008 The example I posted works as expected. Link to comment Share on other sites More sharing options...
randallc Posted January 2, 2008 Share Posted January 2, 2008 Hi, Not sure what you are saying? Do you really believe simple "ArraySort" has such a capability except by coincidence? How yould yo get this to sort on cols 1, then with subsort on 3? ; SubsotrtWeaponX.au3 #include <Array.au3> Dim $array[8][4]=[["C","A","A","C"],["A","A","A","D"],["D","A","D","A"],["A","A","C","B"],["C","A","A","C"],["A","A","A","D"],["D","A","D","A"],["A","A","C","B"]] _ArrayDisplay($array) _ArraySort($array, 0,0,0,UBound($array,2),1) _ArrayDisplay($array) _ArraySort($array, 0,0,0,UBound($array,2),3) _ArrayDisplay($array) ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
weaponx Posted January 3, 2008 Share Posted January 3, 2008 All I said was that the example works. Maybe it is too simple. Link to comment Share on other sites More sharing options...
SiteMaze Posted January 3, 2008 Author Share Posted January 3, 2008 I haven't yet tried out the suggestions yet, but will try out soon. I have another question: Can I achived multikey sort by merging the respective columns? for example, 1. Merge 2d array into a 1d array [1 2 3 3, A B D C] > [1A 2B 3D 3C] 2. _ArraySort on 1d array What are the drawbacks? Arsenal Football Fan Club in Singapore Link to comment Share on other sites More sharing options...
randallc Posted January 3, 2008 Share Posted January 3, 2008 Hi, I think then it will only sort by string values, and only if lengths of each item are the same. Best, randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now