汉字转拼音
来源:互联网 发布:西门子组态软件 编辑:程序博客网 时间:2024/06/07 00:37
通讯录 截取联系人姓名的首字母 转字母
if(data.getName()!=null){
//姓名首字母检索
String Spinyin="";//首字母拼音
for(int j=0;j<data.getName().length();j++){
String temp=MyHanziToPinyin.toPinYin(data.getName().substring(j, j+1));
if(temp!=null&&temp.length()>0){
Spinyin+=(temp.substring(0, 1));
}
}
public class MyHanziToPinyin {
/*** 返回一个字的拼音
* @param hanzi
* @return
*/
public static String toPinYin(String str){
String restr="";
for(int i=0;i<str.length();i++){
char hanzi=str.charAt(i);
HanyuPinyinOutputFormat hanyuPinyin = new HanyuPinyinOutputFormat();
hanyuPinyin.setCaseType(HanyuPinyinCaseType.LOWERCASE);
hanyuPinyin.setToneType(HanyuPinyinToneType.WITHOUT_TONE);//不要声调
hanyuPinyin.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE);
String[] pinyinArray=null;
try {
//是否在汉字范围内
if(hanzi>=0x4e00 && hanzi<=0x9fa5){
pinyinArray = PinyinHelper.toHanyuPinyinStringArray(hanzi, hanyuPinyin);
}else{
pinyinArray = new String[1];
pinyinArray[0]=String.valueOf(hanzi);
}
} catch (BadHanyuPinyinOutputFormatCombination e) {
e.printStackTrace();
}
// 将汉字返回
restr+=pinyinArray[0];
}
return restr;
}
}
0 0
- 汉字转拼音
- 汉字转拼音缩写
- 汉字转拼音缩写
- 实用汉字转拼音
- 汉字转拼音
- 汉字转拼音 asp
- 汉字转拼音缩写
- 汉字转拼音
- 汉字转拼音缩写
- 汉字转拼音
- PHP汉字转拼音
- PHP汉字转拼音
- php汉字转拼音
- java 汉字转拼音
- 汉字转拼音(C#)
- VBS 汉字转拼音
- 汉字转拼音
- 汉字转拼音
- jquery中的$(function(){...})什么时候执行
- dedecms添加新变量提示 Request var not allow
- dede5.7织梦后台广告插件增加图片上传功能
- dede会员邮件验证设置详细图文教程
- RecyclerView的拖动和滑动 第二部分 :拖块,Grid以及自定义动画
- 汉字转拼音
- dedecms获取任意栏目N级列表链接树形菜单-织梦之家
- 架构师基本功:消息队列
- DeDe 父栏目调用可多级支持currentstyle
- 阳历到农历转换的一个PHP类
- 解决WordPress后台一直提示更新翻译
- 2014年07月14日
- syntax error, unexpected $end
- 不带www的域名怎么设置解析