中文转拼音
go get -u github.com/mozillazg/go-pinyin
代码
package main
import (
"bytes"
"example/pholcus/common/pinyin"
"fmt"
)
func main(){
hans := "中国人-你好"
// 默认
a := pinyin.NewArgs()
rows:=pinyin.Pinyin(hans, a)
fmt.Println(rows)
strResult:=""
for i:=0;i<len(rows);i++{
if len(rows[i])!=0{
str:=rows[i][0]
pi:=str[0:1]
strResult+=string(bytes.ToUpper([]byte(pi)))
}
}
fmt.Println(strResult)
}
执行
go run main.go
ZGRNH
网友评论