解决方法有两个,不过我觉得第一个是在有原来转换前的数据时才行得通,第二种个人没测试,不过看过似乎不许前者数据可行通!
第一种如下:
Dim strString As String = "转吧使劲地转吧"
Dim arrByte() As Byte
arrByte = System.Text.Encoding.GetEncoding("GB2312").GetBytes(strString)
For i As Integer = 0 To arrByte.Length - 1
Response.Write(System.Convert.ToString(arrByte(i), 16) & "<br/>")
Next
Response.Write(System.Text.Encoding.GetEncoding("GB2312").GetString(arrByte))
第二种如下:
string sCh = "测试";
sCh = System.Web.HttpUtility.UrlEncode(sCh, System.Text.Encoding.GetEncoding("GB2312")).ToUpper().Replace("%","");
Console.WriteLine(sCh);
System.Web.HttpUtility.UrlEncode(sCh, System.Text.Encoding.GetEncoding("GB2312")).ToUpper()
gives you
%B2%E2%CA%D4
so for "B2E2CAD4 ", just add a % before B2 and E2..-->
%B2%E2%CA%D4
then call HttpUtility.UrlDecode
s=System.Web.HttpUtility.UrlDecode("%B2%E2%CA%D4", System.Text.Encoding.GetEncoding("GB2312"))
第二种本人没测试过,如果你有测试可以告诉下你的测试结果!
字符串与字节转换的两种解决方法
博客介绍了字符串与字节转换的两种解决方法。第一种需有原来转换前的数据,通过编码转换实现;第二种似乎无需前者数据,利用 HttpUtility 进行编码和解码操作,但作者未测试,希望有人分享测试结果。
1055

被折叠的 条评论
为什么被折叠?



