/// <summary>
        /// 解析URL(可以正确识别UTF-8和GB2312编码)
        /// </summary>
        /// <param name="uriString"></param>
        /// <returns></returns>
        public static string DecodeURL(String uriString)
        {
            //正则1:^(?:[\x00-\x7f]|[\xe0-\xef][\x80-\xbf]{2})+$ 
            //正则2:^(?:[\x00-\x7f]|[\xfc-\xff][\x80-\xbf]{5}|[\xf8-\xfb][\x80-\xbf]{4}|[\xf0-\xf7][\x80-\xbf]{3}|[\xe0-\xef][\x80-\xbf]{2}|[\xc0-\xdf][\x80-\xbf])+$
            //如果不考虑哪些什么拉丁文啊,希腊文啊。。。乱七八糟的外文,用短的正则,即正则1
            //如果考虑哪些什么拉丁文啊,希腊文啊。。。乱七八糟的外文,用长的正则,即正则2
            //本方法使用的正则1
            if (Regex.IsMatch(HttpUtility.UrlDecode(uriString, Encoding.GetEncoding("iso-8859-1")), @"^(?:[\x00-\x7f]|[\xe0-\xef][\x80-\xbf]{2})+$"))
            {
                return HttpUtility.UrlDecode(uriString, Encoding.GetEncoding("UTF-8"));
            }
            else
            {
                return HttpUtility.UrlDecode(uriString, Encoding.GetEncoding("GB2312"));
            }
        }
 posted on 2011-06-20 11:57  一直在前进  阅读(736)  评论(0编辑  收藏  举报