Sort the letters of string in alphabetical order

From Rosetta Code
Revision as of 15:50, 24 July 2021 by CalmoSoft (talk | contribs) (Created page with "{{Draft task}} ;Task:Write a function to sort the letters of string in alphabitical order. Write the function even your language has a built-in function for it. <br><br> ==...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Sort the letters of string in alphabetical order is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
Task
Write a function to sort the letters of string in alphabitical order.

Write the function even your language has a built-in function for it.



Ring

<lang ring> see "working..." + nl see "Sort the letters of string in alphabitical order:" + nl str = "forever ring programming language" see "Input: " + str + nl

for n = 1 to len(str)-1

   for m = n+1 to len(str)
       if ascii(str[n]) > ascii(str[m])
          temp = str[n]
          str[n] = str[m]
          str[m] = temp
       ok
   next

next

str = substr(str," ","") see "Output: " + str + nl see "done..." + nl </lang>

Output:
working...
Sort the letters of string in alphabitical order:
Input: forever ring programming language
Output: aaaeeefgggggiilmmnnnooprrrrruv
done...