Page 1 of 1
Sorting a word
Posted: Sun Mar 17, 2013 4:33 pm
by giansuana
I'd like to sort the characters of a word in ascending manner. Thinking of a word as a chunk, I tried something like that (while tWord holding a word):
Code: Select all
sort chars of tWord ascending text
But I get this error: compilation error at line 26 (Chunk: missing chunk) near "chars", char 4.
How can I accomplish my target?
Best, Gian-Reto.
Re: Sorting a word
Posted: Sun Mar 17, 2013 4:46 pm
by sturgis
Probably not the best method (there is probably a way this can be done with a custom sort function) but it should work ok.
Code: Select all
on mouseUp
put "antidisestablishmentarianism" into tWord -- could turn this into a function instead taking a word as a parameter
repeat for each char tChar in tWord -- break the word into items of 1 char
put tChar & comma after tNewWord
end repeat
delete the last char of tNewWord -- remove trailing comma
sort items of tNewWord ascending -- sort by items
replace comma with empty in tNewWord -- nuke the commas
put tNewWord -- if turned into a function this would be "return tNewWord
end mouseUp
Re: Sorting a word
Posted: Sun Mar 17, 2013 4:54 pm
by giansuana
Thank you for your answer. Works great as a function!
