Thứ Hai, 27 tháng 10, 2014

Remove Html Tag, Html Encode/Decode, Url Encode/Decode

Thỉnh thoảng cần dùng, lưu lại cho nhớ.

        public static string RemoveHtml(this string text)
        {
            return Regex.Replace(text, "<[^>]*>", string.Empty);
        }

        public static string HtmlEncode(this string src)
        {
            return System.Net.WebUtility.HtmlEncode(src);
        }

        public static string HtmlDecode(this string src)
        {
            return System.Net.WebUtility.HtmlDecode(src);
        }

        public static string UrlEncode(this string src)
        {
            return System.Web.HttpUtility.UrlEncode(src);
        }

        public static string UrlDecode(this string src)
        {
            return System.Web.HttpUtility.UrlDecode(src);
        }

Không có nhận xét nào :

Đăng nhận xét