通讯录按字母排序的工具类
来源:互联网 发布:河南大学软件学院地址 编辑:程序博客网 时间:2024/06/06 09:00
import net.sourceforge.pinyin4j.PinyinHelper;import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;public class PinYinUtils {/** * 把用户名改成拼音 */public static String getPinYin(String name) {StringBuilder stringBuilder = new StringBuilder();char[] chars = name.toCharArray();HanyuPinyinOutputFormat format = new HanyuPinyinOutputFormat();format.setToneType(HanyuPinyinToneType.WITHOUT_TONE);format.setCaseType(HanyuPinyinCaseType.UPPERCASE);for (char ch : chars) {// 处理空格if (Character.isWhitespace(ch)) {continue;}// ascII 表if (ch > 128 || ch < -127) { // 中文try {String[] strings = PinyinHelper.toHanyuPinyinStringArray(ch, format);if (strings != null && strings.length > 0) {stringBuilder.append(strings[0]);}} catch (BadHanyuPinyinOutputFormatCombination badHanyuPinyinOutputFormatCombination) {badHanyuPinyinOutputFormatCombination.printStackTrace();LogUtil.i("MyInfo",badHanyuPinyinOutputFormatCombination.toString());}} else if ((ch <= 'z' && ch >= 'a') || (ch <= 'Z' && ch >= 'A')) {stringBuilder.append(Character.toUpperCase(ch));}}if (stringBuilder.length() == 0) {stringBuilder.append('|');}return stringBuilder.toString();}}
这个类用到一个jar包:pinyin4j-2.5.0.jar,网上下载下来就行。
0 0
- 通讯录按字母排序的工具类
- ios按字母排序的通讯录
- 电话通讯录demo 包括按字母排序
- 将列表按字母排序如通讯录
- 用系同自带的排序神器对通讯录按字母分组排序
- 类通讯录右侧滑动的字母条
- 自定义SlideBar实现仿通讯录效果按字母排序
- Android实现通讯录功能,排序+字母索引
- 按字母排序的drupal_modules
- Android 实现ListView的A-Z字母排序及过滤搜索功能(通讯录)
- 高仿android通讯录--右边字母排序功能
- (字母排序搜索)类似微信通讯录效果
- Android仿微信通讯录功能,好友排序+字母索引
- Android通讯录字母排序城市列表展示效果
- Android仿微信通讯录功能,好友排序+字母索引
- 仿苹果手机通讯录按字母定位
- JavaScript:按字母排序列表的元素
- LVITEM 的使用 按字母进行排序
- Eclipse工具使用技巧总结
- python-str-format
- VC++获取系统时间,并用字符串显示
- POJ3295Tautology(构造法)
- 看眼图如何分析USB在布线中的信号完整性问题
- 通讯录按字母排序的工具类
- 4. mac xdebug
- Leetcode 410. Split Array Largest Sum 划分数组 解题报告
- Android Gson解析json详解
- 类和对象的基础7——友元函数和友元类
- VS2010(C++)改变对话框背景颜色
- gcc命令参数解析1
- 05-树8 堆中的路径 (25分)
- 通过CGI程序传递checkbox数据 python3