当前位置: 首页 > 工具软件 > JPinyin > 使用案例 >

mysql汉字助记码,利用jpinyin将汉字转化成拼音

狄飞鹏
2023-12-01

添加依赖

com.github.stuxuhai

jpinyin

1.1.8

测试代码

public static void main(String[] args) throws Exception{

String str = "你好世界";

PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITH_TONE_MARK); // nǐ,hǎo,shì,jiè

PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITH_TONE_NUMBER); // ni3,hao3,shi4,jie4

String s = PinyinHelper.convertToPinyinString(str, ",", PinyinFormat.WITHOUT_TONE);// ni,hao,shi,jie

System.out.println(s);

String shortPinyin = PinyinHelper.getShortPinyin(str);// nhsj

System.out.println(shortPinyin);

//PinyinHelper.addPinyinDict("user.dict"); // 添加用户自定义字典

}

 类似资料: