zoukankan      html  css  js  c++  java
  • 获取中文的首字母demo

    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

  • 相关阅读:
    开发日记1
    探索需求2
    探索需求1
    周总结8
    周总结7
    周总结6
    周总结5
    周总结4
    周总结3
    周总结2
  • 原文地址:https://www.cnblogs.com/ipetergo/p/7353570.html
Copyright © 2011-2022 走看看