java提取每个汉字的首字母
2014-03-21 11:24
323 查看
在项目中需要提取每个汉字的首字母,下面是工具类的源码:
需要的jar包下载地址(免积分):http://download.csdn.net/detail/zl544434558/7076087
import net.sourceforge.pinyin4j.PinyinHelper; public class PinyinAPI { /** * 提取每个汉字的首字母(大写) * * @param str * @return */ public static String getPinYinHeadChar(String str) { if (isNull(str)) { return ""; } 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; } } convert = string2AllTrim(convert); return convert.toUpperCase(); } /* * 判断字符串是否为空 */ public static boolean isNull(Object strData) { if (strData == null || String.valueOf(strData).trim().equals("")) { return true; } return false; } /** * 去掉字符串包含的所有空格 * * @param value * @return */ public static String string2AllTrim(String value) { if (isNull(value)) { return ""; } return value.trim().replace(" ", ""); } public static void main(String[] args) { String ss = PinyinAPI.getPinYinHeadChar("中国"); System.out.print(ss);//ZG } }
需要的jar包下载地址(免积分):http://download.csdn.net/detail/zl544434558/7076087
相关文章推荐
- java提取每个汉字的首字母
- Java 常用工具类(2) : 提取汉字首字母工具类
- 【Java习作】提取汉字拼音首字母(Java版)
- java提取字符串中汉字、数字、字母
- 将汉字转换为全拼 、提取每个汉字的首字母
- 用Java显示获取每个汉字的拼音首字母
- 提取汉字拼音首字母(Java版)
- 将汉字转换为全拼 、提取每个汉字的首字母
- java取出一组中文每个汉字的首字母 如 :中国 zg
- java汉字首字母提取
- 提取每个汉字的首字母
- 提取汉字拼音首字母(Java版)
- 提取汉字拼音首字母(Java版)
- C# 汉字转拼音 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母
- MFC下的汉字串拼音首字母提取
- java获取汉字拼音首字母
- C# 使用微软的Visual Studio International Pack 类库提取汉字拼音首字母 转
- JAVA实现汉字转全拼或首字母
- Java获取获取汉字拼音和首字母代码
- java中汉字转换成拼音首字母