字符串与unicode之间转换

public static String unicode2Str(String unicode){
		StringBuffer str=new StringBuffer();
		String[] hex=unicode.split("\\\\u");
		for(int i=0;i<hex.length;i++){
			str.append(hex[i]);
		}
		
		return str.toString();
	}
public static String str2Unicode(String str){
		StringBuffer unicode=new StringBuffer();
		for(int i=0;i<str.length();i++){
			char c=str.charAt(i);
			unicode.append("\\u"+Integer.toHexString(c));
		}
		return unicode.toString();
	}

猜你喜欢

转载自endless.iteye.com/blog/2299718