golang计算字符串长度

golang计算字符串长度

计算字符串长度有两种情况,一种是 ascii 字符,另一种为本地编码 (如:utf8) 的字符。

package main

import "fmt"
import "unicode/utf8"

func main() {
    fmt.Println("Hello, 世界", len("世界"), utf8.RuneCountInString("世界"))
}

猜你喜欢

转载自blog.csdn.net/robin912/article/details/80753638