Sort the letters of string in alphabetical order: Difference between revisions
Sort the letters of string in alphabetical order (view source)
Revision as of 06:42, 26 November 2022
, 1 year agono edit summary
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
No edit summary |
||
Line 515:
print sorted</syntaxhighlight>
{{out}}<pre>aaaaaaaaaabbccddddddddeeeeeeeeefgggghiiIiiiiklmmmnnnnnnnnnOooooopprrrrrrrstttuuuvwwyyyy</pre>
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
local fn AlphabetizeString( string as CFStringRef, deleteSpaces as BOOL ) as CFStringRef
NSUInteger i, count
CFStringRef tempStr, alphaStr = NULL
CFArrayRef array
if deleteSpaces then tempStr = fn StringByReplacingOccurrencesOfString( string, @" ", @"" ) else tempStr = string
count = fn StringLength( tempStr )
CFMutableArrayRef mutArr = fn MutableArrayWithCapacity(count)
for i = 0 to count -1
CFStringRef chr = fn StringWithFormat( @"%C", fn StringCharacterAtIndex( tempStr, i ) )
MutableArrayInsertObjectAtIndex( mutArr, chr, i )
next
array = fn ArraySortedArrayUsingSelector( mutArr, @"localizedCaseInsensitiveCompare:" )
alphaStr = fn ArrayComponentsJoinedByString( array, @"" )
end fn = alphaStr
CFStringRef testStr
testStr = @"The quick brown fox jumped over the lazy dog's back."
print testStr
print "String alphabetized with spaces included:"
print fn AlphabetizeString( testStr, NO )
print
testStr = @"Now is the time for all good men to come to the aid of their country."
print testStr
print "String alphabetized with spaces deleted:"
print fn AlphabetizeString( testStr, YES )
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
The quick brown fox jumped over the lazy dog's back.
String alphabetized with spaces included:
.'aabbccddeeeefghhijkklmnoooopqrrsTtuuvwxyz
Now is the time for all good men to come to the aid of their country.
String alphabetized with spaces deleted:
.aaccddeeeeeeffghhhiiiillmmmNnnooooooooorrrstttttttuwy
</pre>
=={{header|Go}}==
|