golang判断混合字符长度

Posted on 2017-06-28 21:53  leving  阅读(327)  评论(0)    收藏  举报
blog.golang.org/strings
1、
const nihongo = "日本語" for index, runeValue := range nihongo {   fmt.Printf("%#U starts at byte position %d\n", runeValue, index) }

2、

const nihongo = "日本語"
for i, w := 0, 0; i < len(nihonggo); i+=w {
  runeValue, width := utf8.DecodeRuneInString(nihonggo[i:])
  fmt.Printf("%#U starts at byte position %d\n", runeValue, i)
  w = width
}
 

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3