URL中文编码-创新互联
///
/// GB2312编码
///
/// 待编码字符
///编码结果
标题名称:URL中文编码-创新互联
URL地址:http://azwzsj.com/article/jcocj.html
/// GB2312编码
///
/// 待编码字符
///
1public static string GB2312(string str)
2 {
3 StringBuilder sb = new StringBuilder();
4 //GB2321的编码方式 5 byte[] byStr = System.Text.Encoding.GetEncoding ("GB2312").GetBytes(str);
6 for (int i = 0; i < byStr.Length; i++)
7 {
8 //转换为16进制方式 可选2,8,10,16进制 9 sb.Append(@"%" + Convert.ToString(byStr[i], 16));
10 }
11 return (sb.ToString());
12 }
View Code ///
/// GB2312解码
///
///
///
1 public static string DeGB2312(string str)
2 {
3 byte[] bytes = new byte[str.Split('%').Length ];
4 int i=0;
5 foreach (var item in str.Split('%'))
6 {
7 if (item !="")
8 {
9 //转换为16进制的字节10 bytes[i] = Convert.ToByte(item,16);
11 i++;
12 }
13
14 }
15 //GB2312的解码16 return Encoding.GetEncoding ("GB2312").GetString(bytes);
17 }
View Code ///
/// UTF8编码
///
///
///
1 public static string EnUTF8(string str)
2 {
3 StringBuilder sb = new StringBuilder();
4 byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str);
5 for (int i = 0; i < byStr.Length; i++)
6 {
7 sb.Append(@"%" + Convert.ToString(byStr[i], 16));
8 }
9
10 return (sb.ToString());
11 }
View Code ///
/// UTF8解码
///
///
///
1 public static string DeUTF8(string str)
2 {
3 byte[] bytes = new byte[str.Split('%').Length ];
4 int i=0;
5 foreach (var item in str.Split('%'))
6 {
7 if (item !="")
8 {
9 bytes[i] = Convert.ToByte(item,16);
10 i++;
11 }
12
13 }
14 return Encoding.UTF8.GetString(bytes);
15 }
View Code ///C# 32位md5
///
/// 获得32位的MD5加密
///
/// 加密字符串
///
1 public static string GetMD532(string str)
2 {
3 MD5 md5 = MD5.Create();
4 byte[] d = md5.ComputeHash(Encoding.Default.GetBytes(str));
5 return BitConverter.ToString(d).Replace("-", "").ToLower();
6
7 }
View Code 标题名称:URL中文编码-创新互联
URL地址:http://azwzsj.com/article/jcocj.html