char unicode

908 단어 unicode
http://daoshud1.iteye.com/blog/1879315

/**
	 *    Unicode
	 * 
	 * @param s
	 * @return
	 */
	public static String gbEncoding(final String s) {
		String str = "";
		for (int i = 0; i < s.length(); i++) {
			int ch = (int) s.charAt(i);
			str += "\\u" + Integer.toHexString(ch);
		}
		return str;
	}

	/**
	 * Unicode   
	 * 
	 * @param str
	 * @return
	 */
	public static String encodingtoStr(String str) {
		Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
		Matcher matcher = pattern.matcher(str);
		char ch;
		while (matcher.find()) {
			ch = (char) Integer.parseInt(matcher.group(2), 16);
			str = str.replace(matcher.group(1), ch + "");
		}
		return str;
	}

좋은 웹페이지 즐겨찾기