1. maven

        <dependency>
            <groupId>com.belerweb</groupId>
            <artifactId>pinyin4j</artifactId>
            <version>2.5.0</version>
        </dependency>

2. API

2.1 静态工具类(PinyinHelper)

方法 描述
toHanyuPinyinStringArray(char ch, HanyuPinyinOutputFormat outputFormat) 汉语字符转汉语拼音,outputFormat为输出格式,选填
toTongyongPinyinStringArray(char ch) 汉语字符转通用拼音
通用拼音,是中国台湾地区的一种中文拉丁化拼音法
toWadeGilesPinyinStringArray(char ch) 汉语字符转韦氏拼音
toMPS2PinyinStringArray(char ch) 汉语字符转注音二式
toYalePinyinStringArray(char ch) 汉语字符转耶鲁拼音
耶鲁拼音是一种粤语注音拉丁化方案
toGwoyeuRomatzyhStringArray(char ch) 汉语字符转罗马拼音

2.2 输出格式配置类(HanyuPinyinOutputFormat)

方法 描述
HanyuPinyinOutputFormat() 构造方法
restoreDefault() 重置为默认格式配置
getCaseType()
setCaseType(HanyuPinyinCaseType caseType)
设置字母大小写,默认小写
getToneType()
setToneType(HanyuPinyinToneType toneType)
设置声调的类型,默认用数字表示音标
getVCharType()
setVCharType(HanyuPinyinVCharType charType)
设置字母ü展示类型,默认用"u:"表示ü

2.3 配置常量类

(1) HanyuPinyinToneType   声调的类型

常量 描述
WITHOUT_TONE 无音调
WITH_TONE_NUMBER 1-4数字表示音标
WITH_TONE_MARK 直接用音标符(必须设置WITH_U_UNICODE,否则会抛出异常)

(2) HanyuPinyinVCharType   字母ü展示类型

常量 描述
WITH_V 用v表示ü
WITH_U_AND_COLON 用"u:"表示ü
WITH_U_UNICODE 直接用ü

(3) HanyuPinyinCaseType 字母大小写

常量 描述
LOWERCASE 小写
UPPERCASE 大写

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐