常用函数
import ( “fmt” “unicode/utf8” )
func LearnUtf8() { fmt.Println(utf8.RuneCountInString(“abcdef我”)) fmt.Println(utf8.RuneCountInString(“abcdef”)) fmt.Println(len(“abcdef我”)) fmt.Println(len(“abcdef”)) }
<a name="t10S0"></a>## learnUtf8_test.go```gopackage learnUtf8import "testing"func TestLearnUtf8(t *testing.T) {LearnUtf8()}
执行结果
GOROOT=C:\Program Files\Go #gosetupGOPATH=C:\Users\ligz\go #gosetup"C:\Program Files\Go\bin\go.exe" test -c -o C:\Users\ligz\AppData\Local\Temp\GoLand\___basicproject_learnUtf8__TestLearnUtf8.test.exe basicproject/learnUtf8 #gosetup"C:\Program Files\Go\bin\go.exe" tool test2json -t C:\Users\ligz\AppData\Local\Temp\GoLand\___basicproject_learnUtf8__TestLearnUtf8.test.exe -test.v -test.paniconexit0 -test.run ^\QTestLearnUtf8\E$ #gosetup=== RUN TestLearnUtf87696--- PASS: TestLearnUtf8 (0.00s)PASS进程 已完成,退出代码为 0
