finclip-app-manager/vendor/github.com/Chain-Zhang/pinyin
dengxiangcun d78307b1d4 feat:add vendor 2023-11-02 18:36:36 +08:00
..
.gitignore feat:add vendor 2023-11-02 18:36:36 +08:00
.travis.yml feat:add vendor 2023-11-02 18:36:36 +08:00
LICENSE feat:add vendor 2023-11-02 18:36:36 +08:00
Makefile feat:add vendor 2023-11-02 18:36:36 +08:00
README.md feat:add vendor 2023-11-02 18:36:36 +08:00
codecov.yml feat:add vendor 2023-11-02 18:36:36 +08:00
error.go feat:add vendor 2023-11-02 18:36:36 +08:00
go.mod feat:add vendor 2023-11-02 18:36:36 +08:00
pinyin.go feat:add vendor 2023-11-02 18:36:36 +08:00
pinyin.txt feat:add vendor 2023-11-02 18:36:36 +08:00
resource.go feat:add vendor 2023-11-02 18:36:36 +08:00

README.md

pinyin

Build Status codecov

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 方法是两个汉字之间的分隔符.