• C#URL编码解码演示代码


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Web;
    namespace ConsoleApplication3
    {
        class Program
        {
            static void Main(string[] args)
            {
                jiema();
                //bianma();
            }

          public static void jiema()
            {
                string oStr = "http://www.baidu.com/s?bs=%D6%D0%B9%FA&f=8&wd=%D6%D0%B9%FA";
                //oStr是UrlEncode编码字符串
                Encoding gb2312 = Encoding.GetEncoding("gb2312");
                Encoding utf8 = Encoding.UTF8;
                //首先用utf-8进行解码
                string key = HttpUtility.UrlDecode(oStr, utf8);
                // 将已经解码的字符再次进行编码.
                string encode = HttpUtility.UrlEncode(key, utf8).ToLower();
                //与原来编码进行对比,如果不一致说明解码未正确,用gb2312进行解码
                if (oStr != encode)
                    key = HttpUtility.UrlDecode(oStr, gb2312);

                Console.WriteLine(key);
                Console.ReadKey();
            }

          public static void bianma()
          {
              string oStr = "聚合";
              //oStr是UrlEncode编码字符串
              Encoding gb2312 = Encoding.GetEncoding("gb2312");
              string m = System.Web.HttpUtility.UrlEncode(oStr, gb2312);

              Console.WriteLine(m);
              Console.ReadKey();
          }
        }
    }

  • 相关阅读:
    hdu3613(扩展KMP)
    hdu4333(扩展KMP)
    poj 2185
    指数型母函数
    java高精度hdu4043
    卡特兰数简单应用
    hdu3625(第一类斯特林数)
    卡特兰数和斯特林数(转载)
    hdu4045(递推)
    java 中sendredirect()和forward()方法的区别
  • 原文地址:https://www.cnblogs.com/hackpig/p/1668506.html
Copyright © 2020-2023  润新知