1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Nimで文字列の並び替え

Last updated at Posted at 2021-06-02

文字列をsequenceに変換して並び替え、文字列に戻す。

  • sequenceにする時にtoSeqを使うパターン
sort1.nim
import sequtils
import algorithm 
import strutils

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

  • sequenceにする時に@を使うパターン
sort2.nim
import algorithm 
import strutils

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

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?