汉字转换为拼音
来源:互联网 发布:人工智能语音电话 编辑:程序博客网 时间:2024/06/09 17:02
导入pinyin4j-2.5.0.jar包
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
@SuppressWarnings("finally")
public class PinYinUtil {
public static String toPinYin(String str) {
String py = "";
String[] t = new String[str.length()];
char [] hanzi=new char[str.length()];
for(int i=0;i<str.length();i++){
hanzi[i]=str.charAt(i);
}
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat t1 = new HanyuPinyinOutputFormat();
t1.setCaseType(HanyuPinyinCaseType.LOWERCASE);
t1.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
t1.setVCharType(HanyuPinyinVCharType.WITH_V);
try {
for (int i = 0; i < str.length(); i++) {
if ((str.charAt(i) >= 'a' && str.charAt(i) < 'z')
|| (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z')
|| (str.charAt(i) >= '0' && str.charAt(i) <= '9')) {
py += str.charAt(i);
} else {
t = PinyinHelper.toHanyuPinyinStringArray(hanzi[i], t1);
py=py+t[0];
}
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
return py.trim().toString();
}
}
- 汉字转换为拼音
- 汉字转换为拼音
- 汉字转换为拼音
- 汉字转换为拼音
- 汉字转换为拼音
- 汉字转换为拼音
- 将汉字转换为拼音
- js汉字转换为拼音
- 把汉字转换为拼音
- 汉字转换为拼音缩写
- Java汉字转换为拼音
- C#汉字转换为拼音
- Java汉字转换为拼音
- 汉字转换为拼音(1)
- 汉字转换为拼音(2)
- PHP汉字转换为拼音
- 将汉字转换为拼音
- 汉字名字转换为拼音
- Google反代理
- 友盟奔溃错误分析
- Class.forname的作用
- JAVA中Thread VS Runnalbe
- Android Fragment 真正的完全解析(下)
- 汉字转换为拼音
- hadoop2.6安装篇(hadoop平台搭建)
- Spring之IOC实现原理
- 获取相册图片的路径和图片的名字
- 【thinkPHP3.1.2】关于文件上传路径
- sscanf 其实很强大
- 跨境电商决战代购蚂蚁军团
- 黑马程序员——Java基础---static关键字
- Android那点事-系列之(一)Parcelable和Serializable的区别与使用