C#实现UrlEncode (URL编码)

 

public static string UrlEncode(string str)
        {
            StringBuilder sb = new StringBuilder();
            byte[] byStr = System.Text.Encoding.UTF8.GetBytes(str); //默认是System.Text.Encoding.Default.GetBytes(str)
            for (int i = 0; i < byStr.Length; i++)
            {
                sb.Append(@"%" + Convert.ToString(byStr[i], 16));
            }
           
            return (sb.ToString());
        }

posted on 2012-02-18 13:00  张大大123  阅读(199)  评论(0编辑  收藏  举报

导航