</pre><pre name="code" class="java"><span style="white-space:pre"> </span>/**
* 得到中文全拼
* @param src 需要转化的中文字符串
* @return
*/
public static String getPingYin(String src)
{
char[] t1 = null;
t1 = src.toCharArray();
String[] t2 = new String[t1.length];
HanyuPinyinOutputFormat t3 = new HanyuPinyinOutputFormat();
t3.setCaseType(HanyuPinyinCaseType.LOWERCASE);
t3.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
t3.setVCharType(HanyuPinyinVCharType.WITH_V);
String t4 = "";
int t0 = t1.length;
try
{
for (int i = 0; i < t0; i++)
{
// 判断是否为汉字字符
if (java.lang.Character.toString(t1[i]).matches("[\u4E00-\u9FA5]+"))
{
t2 = PinyinHelper.toHanyuPinyinStringArray(t1[i], t3);
t4 += t2[0];
} else
{
t4 += java.lang.Character.toString(t1[i]);
}
}
return t4;
} catch (BadHanyuPinyinOutputFormatCombination e1)
{
e1.printStackTrace();
}
return t4;
}
</pre><pre name="code" class="java"><span style="white-space:pre"> </span>/**
* 得到中文首字母
* @param str 需要转化的中文字符串
* @return
*/
public static String getPinYinHeadChar(String str)
{
String convert = "";
for (int j = 0; j < str.length(); j++)
{
char word = str.charAt(j);
String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
if (pinyinArray != null)
{
convert += pinyinArray[0].charAt(0);
} else
{
convert += word;
}
}
return convert;
}
</pre><pre name="code" class="java"><span style="white-space:pre"> </span>String s = getPinYinHeadChar("广东省");
System.out.println("得到拼音首字母缩写为:" + s);
StringBuffer sb = new StringBuffer(s);
if (sb.length() > 1)
{
String ss = sb.delete(1, sb.length()).toString();
System.out.println("得到的首字母为:"
+ Character.toUpperCase(ss.toCharArray()[0]) + "");
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有