常用函数
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
```go
package learnUtf8
import "testing"
func TestLearnUtf8(t *testing.T) {
LearnUtf8()
}
执行结果
GOROOT=C:\Program Files\Go #gosetup
GOPATH=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 TestLearnUtf8
7
6
9
6
--- PASS: TestLearnUtf8 (0.00s)
PASS
进程 已完成,退出代码为 0