pinyin.go
368 字节
package converter
import (
"github.com/mozillazg/go-pinyin"
"strings"
)
func ToPinYin(hans string, sep string) string {
a := pinyin.NewArgs()
tmp := pinyin.Pinyin(hans, a)
result := make([]string, 0)
for i := range tmp {
result = append(result, tmp[i]...)
}
py := strings.Join(result, sep)
if len(py) == 0 {
return strings.ToLower(hans)
}
return py
}