Hi
Before I start writing my own sort function I would like to know if Revolution already have sort function that I need.
So, the question is: is there sort function in Revolution where I can provide string (or list, or whatever) as my custom sortKey.
I don't want to sort it by numbers, date or alphabetically. As example, my "sort" string is "ABVGD}E|ZIJKLQMNYOPRST"UFHC:W{"...
Regards
Custom sort
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: Custom sort
Hi Srdjan,
what exactly do you want to sort? Do you want to sort arbitrary long lines/text or do you have a special case e.g. one word on each line/item that you want to sort. If you explain a little what you have in mind maybe there is a solution without rewriting the alphabet.
I don't know of any function that lets you swap wholesale the sortKeys, but you can use custom sort functions in a sort, look up the "sort container" entry in the dictionary and there in the user contributed notes at the buttom. Oliver of Runrev gives an example. That approach possibly be tweaked for your purpose.
regards
Bernd
what exactly do you want to sort? Do you want to sort arbitrary long lines/text or do you have a special case e.g. one word on each line/item that you want to sort. If you explain a little what you have in mind maybe there is a solution without rewriting the alphabet.
I don't know of any function that lets you swap wholesale the sortKeys, but you can use custom sort functions in a sort, look up the "sort container" entry in the dictionary and there in the user contributed notes at the buttom. Oliver of Runrev gives an example. That approach possibly be tweaked for your purpose.
regards
Bernd
Re: Custom sort
I want to sort lines of text.
Thank you for suggestions. I'll check them.
Thank you for suggestions. I'll check them.
Re: Custom sort
Srdjan,
you could map the new sort order to their "usual" sort order in the ASCII table. You would do this in a custom sort function.
eg. you want to sort "AZC"
you would replace in your custom sort function the letter capital Z with capital B, this will not affect your original lines, just the 'behind the scene' sort string.
You could expand this with a look-up table for all your letters. In short you would make e.g. an array that has the characters from ASCII >= 32 up to 255 as a key (or rather the chartonum value of the characters as a key) and the replacement character as a value. You would have to reconstruct the search string in your custom sort function with such a look up table.
Maybe someone comes up with an easier solution.
regards
Bernd
you could map the new sort order to their "usual" sort order in the ASCII table. You would do this in a custom sort function.
eg. you want to sort "AZC"
you would replace in your custom sort function the letter capital Z with capital B, this will not affect your original lines, just the 'behind the scene' sort string.
You could expand this with a look-up table for all your letters. In short you would make e.g. an array that has the characters from ASCII >= 32 up to 255 as a key (or rather the chartonum value of the characters as a key) and the replacement character as a value. You would have to reconstruct the search string in your custom sort function with such a look up table.
Maybe someone comes up with an easier solution.
regards
Bernd
-
- Posts: 230
- Joined: Thu Jul 01, 2010 11:50 am
Re: Custom sort
Why not just tag all your data with regular numbers and then sort by that?
put fld myDataField into myData
put "ABVGD}E|ZIJKLQMNYOPRST" "e& "UFHC:W{" into sortOrder
repeat with counter = 1 to the number of lines of myData
put (offset(char 1 of line counter of myData,sortOrder)) &comma before line counter of myData
end repeat
sort myData numeric by item 1 of each
repeat with counter = 1 to the number of lines of myData
delete item 1 of line counter of myData
end repeat
put myData into fld myDataField