pinyin

package module
v0.0.0-...-c3317c2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 4 Imported by: 0

README

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInitialize = errors.New("not yet initialized")
)

Functions

func New

func New(origin string) *pinyin

Types

type Mode

type Mode int
const (
	WithoutTone        Mode = iota + 1 // 默认模式,例如:guo
	Tone                               // 带声调的拼音 例如:guó
	InitialsInCapitals                 // 首字母大写不带声调,例如:Guo
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL