Skip to content

Instantly share code, notes, and snippets.

@usk81
Last active December 7, 2022 06:17
Show Gist options
  • Save usk81/b1239fb8edf46496fe9a09fb7d68f412 to your computer and use it in GitHub Desktop.
Save usk81/b1239fb8edf46496fe9a09fb7d68f412 to your computer and use it in GitHub Desktop.
五十音順並び替え
package main
import (
"fmt"
"sort"
)
func main() {
ts := []string{"あ","た","ら","し","い","ひ","び"}
sort.Slice(ts, func(i, j int) bool {
// fmt.Printf("i: %v, j:%v\n", i, j)
return ts[i] < ts[j]
})
for _, t := range ts {
fmt.Printf(t)
// => あいしたひびら
}
fmt.Println("")
fmt.Printf("あ > ほ, expected: false, result: %v", "あ" > "ほ")
// => あ > ほ, expected: false, result: false
}
@usk81
Copy link
Author

usk81 commented Mar 27, 2017

簡単なデモ

sortのデフォルト処理だけでもUnicodeの順番でひらがなの並び替えはできるようです。
https://unicode-table.com/en/blocks/hiragana/

Go-Playground
https://play.golang.org/p/lq5SP2FvxK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment