首页 > 其他 > 详细

获取中文的首字母demo

时间:2017-08-13 16:09:30      阅读:163      评论:0      收藏:0      [点我收藏+]
import net.sourceforge.pinyin4j.PinyinHelper;
/**
	 * 
	 * @Title: getPinYinHeadChar
	 * @Description: TODO 获取中文的首字母
	 * @param str 传入的中文参数
	 * @return
	
	 * @return: String 
	 */
	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;
    }

  测试:

System.out.println(PinYinUtil.getPinYinHeadChar("我比较"));===》wbj

获取中文的首字母demo

原文:http://www.cnblogs.com/ipetergo/p/7353570.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!