Jump to content

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

add FreeBASIC
(Added AutoHotkey)
(add FreeBASIC)
Line 199:
aaaaaabdeeeğıilllmMnsşy
</pre>
 
=={{header|FreeBASIC}}==
<lang freebasic>
function value( s as string ) as integer
'maps a=A=0, b=B=1, etc
return asc(ucase(s))-65
end function
 
sub sortstr( ins as string, outs as string )
dim as string c
dim as integer cv, i, j
outs = ""
for i = 1 to len(ins)
c = mid(ins,i,1)
cv = value(c)
if cv > 25 or cv < 0 then continue for 'this isn't a letter so don't output it
for j = 1 to len(outs)
if value(mid(outs,j,1))>cv then exit for
next j
outs = left(outs,j-1) + c + right(outs,len(outs)-j+1)
next i
end sub
 
dim as string example = "Once upon a midnight dreary as I pondered weak and weary over many a dumb and buggy line of irritating code"
dim as string sorted
 
sortstr( example, sorted )
print sorted</lang>
{{out}}<pre>aaaaaaaaaabbccddddddddeeeeeeeeefgggghiiIiiiiklmmmnnnnnnnnnOooooopprrrrrrrstttuuuvwwyyyy</pre>
 
=={{header|Go}}==
781

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.