java如何把中文字符转成\u53d1\u9001\u6210\u529fs这种格式
2个回答
展开全部
你这个是UNCODE码,只需要使用java程序转换一下就可以了,下面有个简单的小例子!
public class UncodeTest {
public static String getUncode(String str)
{
if(str==null)return "";
String hs="";
try
{
byte b[]=str.getBytes("UTF-16");
for (int n=0;n<b.length;n++)
{
str=(java.lang.Integer.toHexString(b[n] & 0XFF));
if (str.length()==1)
hs=hs+"0"+str;
else
hs=hs+str;
if (n<b.length-1)hs=hs+"";
}
//去除第一个标记字符
str= hs.toUpperCase().substring(4);
char[] chs=str.toCharArray();
str="";
for(int i=0;i<chs.length;i=i+4)
{
str+="\\u"+chs[i]+chs[i+1]+chs[i+2]+chs[i+3];
}
return str;
}
catch(Exception e)
{
System.out.print(e.getMessage());
}
return str;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = UncodeTest.getUncode("发送成功!");
System.out.println(s);
}
}
PS:有问题可Hi我,good luck!
public class UncodeTest {
public static String getUncode(String str)
{
if(str==null)return "";
String hs="";
try
{
byte b[]=str.getBytes("UTF-16");
for (int n=0;n<b.length;n++)
{
str=(java.lang.Integer.toHexString(b[n] & 0XFF));
if (str.length()==1)
hs=hs+"0"+str;
else
hs=hs+str;
if (n<b.length-1)hs=hs+"";
}
//去除第一个标记字符
str= hs.toUpperCase().substring(4);
char[] chs=str.toCharArray();
str="";
for(int i=0;i<chs.length;i=i+4)
{
str+="\\u"+chs[i]+chs[i+1]+chs[i+2]+chs[i+3];
}
return str;
}
catch(Exception e)
{
System.out.print(e.getMessage());
}
return str;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
String s = UncodeTest.getUncode("发送成功!");
System.out.println(s);
}
}
PS:有问题可Hi我,good luck!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询