java获取首字母 |
您所在的位置:网站首页 › 获取中文首字母 › java获取首字母 |
获取一个字符串的首字母是中文排序以及按照字母搜索的基础,一下是实现一个字符串转换为每个汉字首字母的字符串 //根据一个包含汉字的字符串返回一个汉字拼音首字母的字符串 public String getLetterOfString(String SourceStr){ String Result = ""; int StrLength = SourceStr.length(); int i; try { for (i = 0; i < StrLength; i++) { Result += getUpper(SourceStr.charAt(i)); } } catch (Exception e) { Result = ""; } System.out.println("获取首字母:"+SourceStr+"letter:"+Result); return Result; } public char getUpper(char ch) { if (ch >= 'a' && ch = 'A' && ch = 26)return '0'; else return upperLetter[i]; } private char[] upperLetter = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; private int gbValue(char ch) { String str = new String(); str += ch; try { byte[] bytes = str.getBytes("GBK"); if (bytes.length < 2) return 0; return (bytes[0] |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |