public static string ToUrlEncode(string strCode) { StringBuilder sb = new StringBuilder(); byte[] byStr = Encoding.UTF8.GetBytes(strCode); Regex regKey = new Regex("^[A-Za-z0-9]+$"); for (int i = 0; i < byStr.Length; i++) { string strBy = Convert.ToChar(byStr[i]).ToString(CultureInfo.InvariantCulture); if (regKey.IsMatch(strBy)) { //是字母或者数字则不进行转换 sb.Append(strBy); } else { sb.Append(@"" + Convert.ToString(byStr[i], 16).ToUpper()); } } return (sb.ToString()); }