替换地址栏汉字的方法

   public string getUrl(string url)
        {
            MatchCollection mats = Regex.Matches(url, "(?<first>[\\w]*)=(?<two>[\u4e00-\u9fa5]*)", RegexOptions.IgnoreCase | RegexOptions.Multiline);
            foreach (Match mat in mats)
            {
                //Response.Write(mat.Groups["first"].Value + "----");
                //Response.Write(mat.Groups["two"].Value + "------2");
                url = url.Replace(mat.Groups["first"].Value + "=" + mat.Groups["two"].Value, mat.Groups["first"].Value + "=" + HttpUtility.UrlEncodeUnicode(mat.Groups["two"].Value.Trim()));
                // Response.Write(url.Replace(mat.Groups["first"].Value + "=" + mat.Groups["two"].Value, mat.Groups["first"].Value + "=" + HttpUtility.UrlEncode(mat.Groups["two"].Value.Trim())));
                //Response.Write(HttpUtility.UrlDecode(HttpUtility.UrlEncode(mat.Groups["two"].Value.Trim())));
            }
            return url;
        }

你可能感兴趣的:(方法)