码迷,mamicode.com
首页 > Windows程序 > 详细

c#编码转换

时间:2015-09-06 23:05:15      阅读:384      评论:0      收藏:0      [点我收藏+]

标签:

       /// <summary>
        /// URL编码
        /// </summary>
        /// <param name="Source"></param>
        /// <param name="Encod">是否UTF8</param>
        /// <param name="toUpper">默认到大写</param>
        /// <returns></returns>
        public static string URLEncod(string Source, Encoding Encod, bool toUpper = true)
        {
            if (toUpper)
            {
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < Source.Length; i++)
                {
                    string t = Source[i].ToString();
                    string k = HttpUtility.UrlEncode(t, Encod);
                    if (t == k) sb.Append(t);
                    else sb.Append(k.ToUpper());
                }
                return sb.ToString();
            }
            else
                return HttpUtility.UrlEncode(Source, Encod);
            
        }
        /// <summary>
        /// URL解码
        /// </summary>
        /// <param name="Source"></param>
        /// <param name="Encod">是否UTF8</param>
        /// <returns></returns>
        public static string URLDecode(string Source, Encoding Encod)
        {

            return HttpUtility.UrlDecode(Source, Encod);
        }

 

c#编码转换

标签:

原文地址:http://www.cnblogs.com/milest/p/4787566.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!