一、需要的包:
go get github.com/mozillazg/go-pinyin
二、具体代码:
import (
"fmt"
"github.com/mozillazg/go-pinyin"
"strings"
)
func main() {
fmt.Println(ChinaToPinYin("迪迦奥特曼"))
}
func ChinaToPinYin(s string) string {
a := pinyin.LazyConvert(s, nil)
var test string
for _, name := range a {
one := name[0:1]
upper := strings.ToUpper(one)
end := name[1:len(name)]
name = upper + end
test = test + name
}
return test
}
三、结果
DiJiaAoTeMan
可以当作自己的小工具