DEV Community

Cover image for Sort String  In Nim
sjuny
sjuny

Posted on

Sort String In Nim

to sequence, sort, and join sequence.

  • using toSeq
import sequtils
import algorithm 
import strutils

let value = "54321"
let sortedChars = toSeq(value.items).sorted(cmp)
echo sortedChars.join() #12345

Enter fullscreen mode Exit fullscreen mode
  • using @
import algorithm 
import strutils

let value = "54321"
let sortedChars = @value.sorted(cmp)
echo sortedChars.join() #12345

Enter fullscreen mode Exit fullscreen mode

Top comments (2)

Collapse
 
juancarlospaco profile image
Juan Carlos
import std/[algorithm, strutils]
echo "453678790".sorted.join
Enter fullscreen mode Exit fullscreen mode
Collapse
 
sjuny profile image
sjuny

It's very short. So nice!