HexEscape() public static method

public static HexEscape ( char character ) : string
character char
return string
Ejemplo n.º 1
0
        /// <summary>
        /// 编码汉字
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string Escape(this string str)
        {
            StringBuilder sb = new StringBuilder();

            foreach (char c in str)
            {
                sb.Append((Char.IsLetterOrDigit(c) || c == '-' || c == '_' || c == '\\' || c == '/' || c == '.') ? c.ToString() : Uri.HexEscape(c));
            }
            return(sb.ToString());
        }