DEV Community

Cover image for Sort String  In Nim
sjuny
sjuny

Posted on

4 2

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!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay