Delta Posted July 1, 2008 Share Posted July 1, 2008 Is it possible to order the lines read from a file? for instance: Line 1 = ID44563 - james Line 2 = ID12345 - joe Line 3 = ID34392 - jeff should change to: Line 1 = ID12345 - joe Line 2 = ID34392 - jeff Line 3 = ID44563 - james [size="1"]Please stop confusing "how to" with "how do"[/size] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 1, 2008 Share Posted July 1, 2008 Is it possible to order the lines read from a file? for instance:Line 1 = ID44563 - jamesLine 2 = ID12345 - joeLine 3 = ID34392 - jeffshould change to: Line 1 = ID12345 - joeLine 2 = ID34392 - jeffLine 3 = ID44563 - james_FileReadToArray()_ArraySort() Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Delta Posted July 1, 2008 Author Share Posted July 1, 2008 Unfortunately all that does is create a ton of blank array entries. I think I have another solution though If I figure it out I'll post it. [size="1"]Please stop confusing "how to" with "how do"[/size] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 1, 2008 Share Posted July 1, 2008 Unfortunately all that does is create a ton of blank array entries. I think I have another solution though If I figure it out I'll post it. You give up way to easily: #include <Array.au3> Global $avFile, $sFile = "C:\Temp\MyFile.txt" ; Read File _FileReadToArray($sFile, $avFile) ; Remove blank lines For $n = $avFile[0] To 1 Step -1 If StringStripWS($avFile[$n], 8) = "" Then _ArrayDelete($avFile, $n) Next $avFile[0] = UBound($avFile) - 1 ; Sort _ArraySort($avFile, 0, 1) ; Display _ArrayDisplay($avFile, "$avFile") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Delta Posted July 2, 2008 Author Share Posted July 2, 2008 (edited) There are no blank lines in the file. _FileReadToArray [0] returns the number of entries in the array. After you do array sort it changes the position of [0] and for some reason adds a ton of blank entries. However I figured out an easier way was to just use the sort function on the listbox. Edited July 2, 2008 by Deltaforce229 [size="1"]Please stop confusing "how to" with "how do"[/size] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 2, 2008 Share Posted July 2, 2008 There are no blank lines in the file. _FileReadToArray [0] returns the number of entries in the array. After you do array sort it changes the position of [0] and for some reason adds a ton of blank entries. However I figured out an easier way was to just use the sort function on the listbox. I don't recall a listbox being mentioned before. There may be easier ways to do what you want, more power to 'ya. But [0] is not moved by the code I posted because the third parameter of _ArraySort() is the index to start at, which is set to 1. Even if it doesn't help with your current application, you might try the code posted just to learn how it works (after adding "#include <File.au3>", which I missed in the copy/paste). _ArraySort() also does not add any blank 'entries'. Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Delta Posted July 6, 2008 Author Share Posted July 6, 2008 (edited) Sorry to get back to you so late on this but i have been dealing with a lot of crap lately and haven't had time to post. The method you posted removes lines and replaces them with blank ones. I have a file that contains 4757 ids. After your method I'm left with only 3999 ids and 758 blank lines. The method does sort the lines but it deletes them too. Edit: A thought just came to mind. Would characters such as | or , or . ect. effect the sort? Edited July 6, 2008 by Deltaforce229 [size="1"]Please stop confusing "how to" with "how do"[/size] Link to comment Share on other sites More sharing options...
PsaltyDS Posted July 7, 2008 Share Posted July 7, 2008 Sorry to get back to you so late on this but i have been dealing with a lot of crap lately and haven't had time to post.The method you posted removes lines and replaces them with blank ones. I have a file that contains 4757 ids. After your method I'm left with only 3999 ids and 758 blank lines. The method does sort the lines but it deletes them too.Edit: A thought just came to mind. Would characters such as | or , or . ect. effect the sort?If you already have code that works, we needn't carry on with this. But if you want to investigate this alternative, we need some sample data (Not 5K lines worth!) to illustrate what you are dealing with. muttley Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law 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