golang计算字符串长度
计算字符串长度有两种情况,一种是 ascii 字符,另一种为本地编码 (如:utf8) 的字符。
package main
import "fmt"
import "unicode/utf8"
func main() {
fmt.Println("Hello, 世界", len("世界"), utf8.RuneCountInString("世界"))
}
计算字符串长度有两种情况,一种是 ascii 字符,另一种为本地编码 (如:utf8) 的字符。
package main
import "fmt"
import "unicode/utf8"
func main() {
fmt.Println("Hello, 世界", len("世界"), utf8.RuneCountInString("世界"))
}