從別人處copy過來的,實用,備用
/**
* 字符串轉unicode
*/
public static String convert(String str) {
str = (str == null ? "" : str);
String tmp;
StringBuffer sb = new StringBuffer(1000);
char c;
int i, j;
sb.setLength(0);
for (i = 0; i < str.length(); i++) {
c = str.charAt(i);
sb.append("\\u");
System.out.println(c);
j = (c >>> 8); // 取出高8位
System.out.println("j = " + j);
tmp = Integer.toHexString(j);
System.out.println(tmp);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
j = (c & 0xFF); // 取出低8位
System.out.println("j = " + j);
tmp = Integer.toHexString(j);
System.out.println(tmp);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
}
return (new String(sb));
}