资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

URL中文编码-创新互联

       ///
       /// GB2312编码
      ///

       /// 待编码字符
       /// 编码结果
      URL中文编码
 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中文编码-创新互联
网站链接:http://cdkjz.cn/article/jcocj.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220