第1个回答 推荐于2018-05-17
using System.Text;
byte[] buffer = Encoding.GetEncoding("utf-8").GetBytes("中国");
string str = "";
foreach (byte b in buffer) str += string.Format("%{0:X}", b);本回答被提问者和网友采纳
第2个回答 2009-05-07
private void button1_Click(object sender, EventArgs e)
{
string temp = string.Empty;
UTF8Encoding utf8 = new UTF8Encoding();
byte[] encodedBytes = utf8.GetBytes("中国");
foreach (byte b in encodedBytes)
{
temp+="%"+b.ToString("X");
}
MessageBox.Show(temp);
}
试试吧,应该是你想要的了,或者以下这种形式:
string temp = string.Empty;
byte[] encodedBytes = Encoding.GetEncoding("utf-8").GetBytes("中国");
foreach (byte b in encodedBytes)
{
temp+="%"+b.ToString("X");
}
MessageBox.Show(temp);
第3个回答 2009-05-07
使用 //Byte[] bytes = System.Text.Encoding.UTF8.GetBytes("中国");
第4个回答 2009-05-07
直接引用System.Web
然后用里面的System.Web.Ultility.UrlEncode
有重载,第二个参数可以定义什么样的编码
第5个回答 2009-05-07
这个是用 Server.HTMLEncode 编码的~ 解码时用 Server.HTMLDecod
还有 Server.URLEncode 和 Server.URLDecod