Sort the letters of string in alphabetical order: Difference between revisions

Content added Content deleted
(Added AutoHotkey)
Line 77: Line 77:
<pre> sort 'Now is the time for all good men to come to the aid of their country.'
<pre> sort 'Now is the time for all good men to come to the aid of their country.'
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>

=={{header|AutoHotkey}}==
<lang AutoHotkey>sortLetters(str, RemoveSpace := 1){
oChar := []
for i, v in StrSplit(str)
if (v <> " ") && RemoveSpace
oChar[Asc(v), i] := v
else if !RemoveSpace
oChar[Asc(v), i] := v
for ascii, obj in oChar
for i, letter in obj
result .= letter
return result
}</lang>
Examples:<lang AutoHotkey>str1 := "The quick brown fox jumps over the lazy dog, apparently"
str2 := "Now is the time for all good men to come to the aid of their country."

MsgBox, 262144, , % result := str1 " ->`n" sortLetters(str1)
. "`n`n" str2 " ->`n" sortLetters(str2, 0)</lang>
{{out}}
<pre>The quick brown fox jumps over the lazy dog, apparently ->
,Taaabcdeeeefghhijkllmnnoooopppqrrrsttuuvwxyyz

Now is the time for all good men to come to the aid of their country. ->
.Naaccddeeeeeeffghhhiiiillmmmnnooooooooorrrstttttttuwy</pre>

=={{header|AWK}}==
=={{header|AWK}}==
<lang AWK>
<lang AWK>