/**
* 中文信息转Unicode编码
*/
public class Tools
{
/**
* 中文信息转Unicode编码
* @param args
*/
public static void main(String[] args)
{
Tools tools = new Tools();
String b = "中国移动提醒您:系统设备问题,暂时无法提供服务!";
System.out.println(b+" 转Unicode编码为:/r/n"+tools.convert(b));
}
/**
* 中文信息转Unicode编码
* @param strSrc 需要转换的字符串
* @return Unicode编码后的字符串
*/
private String convert(String strSrc)
{
String tmp;
StringBuffer sb = new StringBuffer(1000);
char c;
int i, j;
sb.setLength(0);
for (i = 0; i < strSrc.length(); i++)
{
c = strSrc.charAt(i);
if (c > 255)
{
sb.append("//u");
j = (c >>> 8);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
j = (c & 0xFF);
tmp = Integer.toHexString(j);
if (tmp.length() == 1)
sb.append("0");
sb.append(tmp);
}
else
{
sb.append(c);
}
}
return (new String(sb));
}
}