I got a question here.I need to get the pinyin of a Chinese word using golang.For example:
What I want to get from Chinese "世界" is letter "S" except "世".
Can go language do this automatically?
I got a question here.I need to get the pinyin of a Chinese word using golang.For example:
What I want to get from Chinese "世界" is letter "S" except "世".
Can go language do this automatically?
Use github.com/mozillazg/go-pinyin
package main
import (
"fmt"
"github.com/mozillazg/go-pinyin"
)
var a = pinyin.NewArgs()
func FirstLetterOfPinYin(r rune) string {
result := pinyin.Pinyin(string(r), a)
return string(result[0][0][0])
}
func main() {
fmt.Println(FirstLetterOfPinYin('世'))
fmt.Println(FirstLetterOfPinYin('界'))
}
If you have string of Chinese characters, you can range the string to get rune of the chars.