码迷,mamicode.com
首页 > 移动开发 > 详细

Android_Unicode码转为汉字

时间:2014-11-04 11:06:58      阅读:240      评论:0      收藏:0      [点我收藏+]

标签:unicode   string   java   android   

public static String decode(String unicodeStr) {
	if (unicodeStr == null) {
		return null;
	}
	StringBuffer retBuf = new StringBuffer();
	int maxLoop = unicodeStr.length();
	for (int i = 0; i < maxLoop; i++) {
		if (unicodeStr.charAt(i) == '\\') {
			if ((i < maxLoop - 5) && ((unicodeStr.charAt(i + 1) == 'u') || (unicodeStr.charAt(i + 1) == 'U')))
				try {
					retBuf.append((char) Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));
					i += 5;
				} catch (NumberFormatException localNumberFormatException) {
					retBuf.append(unicodeStr.charAt(i));
				}
			else
				retBuf.append(unicodeStr.charAt(i));
		} else {
			retBuf.append(unicodeStr.charAt(i));
		}
	}
	return retBuf.toString();
}

Android_Unicode码转为汉字

标签:unicode   string   java   android   

原文地址:http://blog.csdn.net/zimo2013/article/details/40780439

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!