package main import ( "fmt" "unicode/utf8" ) func main() { str:="?表情" fmt.Println(utf8.RuneCountInString(str)) fmt.Println(len(str)) slice:=str[0:10] fmt.Println(slice) nameRune := []rune(str) fmt.Println(len(nameRune)) fmt.Println("string = ",string(nameRune[0:len(nameRune)])) }
output:
3
10
?表情
3
string = ?表情