java处理unicode_C# JavaScript Java 与 中文 unicode 处理

C#

// 将汉字转换为Unicode

//要转换的字符串///public static string GBToUnicode(string text)

{

byte[] bytes = System.Text.Encoding.Unicode.GetBytes(text);

string lowCode = "", temp = "";

for (int i = 0; i

{

if (i % 2==0)

{

temp= System.Convert.ToString(bytes[i],16);//取出元素4编码内容(两位16进制)

if (temp.Length 

}

else

{

string mytemp= Convert.ToString(bytes[i],16);

if (mytemp.Length 

}

}

return lowCode;

}

/// /// 将Unicode转换为汉字

//要转换的字符串///public string UnicodeToGB(string text)

{

MatchCollection mc = Regex.Matches(text, "([\\w]+)|(\\\\u([\\w]{4}))");

if (mc != null && mc.Count > 0)

{

StringBuilder sb = new StringBuilder();

foreach (Match m2 in mc)

{

string v = m2.Value;

string word = v.Substring(2);

byte[] codes = new byte[2];

int code = Convert.ToInt32(word.Substring(0, 2), 16);

int code2 = Convert.ToInt32(word.Substring(2), 16);

codes[0] = (byte)code2;

codes[1] = (byte)code;

sb.Append(Encoding.Unicode.GetString(codes));

}

return sb.ToString();

}

else

{

return text;

}

}

jsvarclassObj={

ToUnicode:function(str)

{returnescape(str).replace(/%/g,"\\").toLowerCase();

},

UnUnicode:function(str)

{returnunescape(str.replace(/\\/g,"%"));

},

copyingTxt:function(str)

{

document.getElementById(str).select();

document.execCommand("Copy");

}

}Java:

public static void main(String[] args) {

String str = "\u4e2d\u534e\u4eba\u6c11\u5171\u548c\u56fd";

//char[] charArray = str.toCharArray();

//str = new String(charArray);

System.out.println(str);

System.out.print(str.equals("中华人民共和国"));

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值