package
module
Version:
v0.1.3
Opens a new window with list of versions in this module.
Published: Dec 3, 2019
License: MIT
Opens a new window with license information.
Imports: 4
Opens a new window with list of imports.
Imported by: 12
Opens a new window with list of known importers.
README
¶
pinyin
golang实现中文汉字转拼音
demo
package main
import(
"fmt"
"github.com/chain-zhang/pinyin"
)
func main() {
str, err := pinyin.New("我是中国人").Split("").Mode(InitialsInCapitals).Convert()
if err != nil {
// 错误处理
}else{
fmt.Println(str)
}
str, err = pinyin.New("我是中国人").Split(" ").Mode(pinyin.WithoutTone).Convert()
if err != nil {
// 错误处理
}else{
fmt.Println(str)
}
str, err = pinyin.New("我是中国人").Split("-").Mode(pinyin.Tone).Convert()
if err != nil {
// 错误处理
}else{
fmt.Println(str)
}
str, err = pinyin.New("我是中国人").Convert()
if err != nil {
// 错误处理
}else{
fmt.Println(str)
}
}
输出
WoShiZhongGuoRen
wo shi zhong guo ren
wǒ-shì-zhōng-guó-rén
wo shi zhong guo ren
Mode 介绍
InitialsInCapitals
: 首字母大写, 不带音调
WithoutTone
: 全小写,不带音调
Tone
: 全小写带音调
Split 介绍
split 方法是两个汉字之间的分隔符.
Documentation
¶
func New(origin string) *pinyin
const (
WithoutTone Mode = iota + 1
Tone
InitialsInCapitals
)
Source Files
¶
Click to show internal directories.
Click to hide internal directories.