这是什么码?\u8bf7\u9009\u62e9 在IE里显示是 请选择

lanxe 2006-03-31 04:19:19
这是什么码?\u8bf7\u9009\u62e9 在IE里显示是 请选择
在C#里怎么才可以把“请选择”转为 \u8bf7\u9009\u62e9 的代码?
...全文
668 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
lanxe 2006-03-31
  • 打赏
  • 举报
回复
谢谢net_lover(孟子E章)!
liudng(大东) ,MSDN里这段代码是有问题的。
孟子E章 2006-03-31
  • 打赏
  • 举报
回复
public string CharacterToCoding(string character)
{
string coding = "";
for (int i = 0; i<character.Length; i++ )
{
byte[] bytes = System.Text.Encoding.Unicode.GetBytes(character.Substring(i,1)); //取出二进制编码内容
string lowCode = System.Convert.ToString(bytes[0], 16); //取出低字节编码内容(两位16进制)
if (lowCode.Length == 1)
lowCode = "0" + lowCode;
string hightCode = System.Convert.ToString(bytes[1], 16);//取出高字节编码内容(两位16进制)
if (hightCode.Length == 1)
hightCode = "0" + hightCode;
coding += "\\u"+ (hightCode +lowCode);//加入到字符串中,
}
return coding;
}
孟子E章 2006-03-31
  • 打赏
  • 举报
回复
参考这个
http://www.webasp.net/article/13/12542.htm
不过取的有点需要修改
liudng 2006-03-31
  • 打赏
  • 举报
回复
using System;
using System.Text;

class UnicodeEncodingExample {
public static void Main() {
// The encoding.
UnicodeEncoding unicode = new UnicodeEncoding();

// Create a string that contains Unicode characters.
String unicodeString =
"This Unicode string contains two characters " +
"with codes outside the traditional ASCII code range, " +
"Pi (\u03a0) and Sigma (\u03a3).";
Console.WriteLine("Original string:");
Console.WriteLine(unicodeString);

// Encode the string.
Byte[] encodedBytes = unicode.GetBytes(unicodeString);
Console.WriteLine();
Console.WriteLine("Encoded bytes:");
foreach (Byte b in encodedBytes) {
Console.Write("[{0}]", b);
}
Console.WriteLine();

// Decode bytes back to string.
// Notice Pi and Sigma characters are still present.
String decodedString = unicode.GetString(encodedBytes);
Console.WriteLine();
Console.WriteLine("Decoded bytes:");
Console.WriteLine(decodedString);
}
}

rola 2006-03-31
  • 打赏
  • 举报
回复
楼主是反编译代码得到的吧,^_^,就像上面的朋友说的,是unicode
conan19771130 2006-03-31
  • 打赏
  • 举报
回复
这是unicode

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧