| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- using System.Web;
- namespace RMYY_CallCenter_Api.Utility
- {
- public class WebHelper
- {
- #region UrlDecode(对Url进行解码)
- /// <summary>
- /// 对Url进行解码,对于javascript的encodeURIComponent函数编码参数,应使用utf-8字符编码来解码
- /// </summary>
- /// <param name="url">url</param>
- public static string UrlDecode(string url)
- {
- return HttpUtility.UrlDecode(url);
- }
- /// <summary>
- /// 对Url进行解码,对于javascript的encodeURIComponent函数编码参数,应使用utf-8字符编码来解码
- /// </summary>
- /// <param name="url">url</param>
- /// <param name="encoding">字符编码,对于javascript的encodeURIComponent函数编码参数,应使用utf-8字符编码来解码</param>
- public static string UrlDecode(string url, Encoding encoding)
- {
- return HttpUtility.UrlDecode(url, encoding);
- }
- #endregion
- #region 去除HTML标记
- /// <summary>
- /// 去除HTML标记
- /// </summary>
- /// <param name="NoHTML">包括HTML的源码 </param>
- /// <returns>已经去除后的文字</returns>
- public static string NoHtml(string Htmlstring)
- {
- //删除脚本
- Htmlstring = Regex.Replace(Htmlstring, @"<script[^>]*?>.*?</script>", "", RegexOptions.IgnoreCase);
- //删除HTML
- Htmlstring = Regex.Replace(Htmlstring, @"<(.[^>]*)>", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"([\r\n])[\s]+", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"-->", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"<!--.*", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(quot|#34);", "\"", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(amp|#38);", "&", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(lt|#60);", "<", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(gt|#62);", ">", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(nbsp|#160);", " ", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(iexcl|#161);", "\xa1", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(cent|#162);", "\xa2", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(pound|#163);", "\xa3", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&(copy|#169);", "\xa9", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"&#(\d+);", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"…", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"—", "", RegexOptions.IgnoreCase);
- Htmlstring = Regex.Replace(Htmlstring, @"“", "", RegexOptions.IgnoreCase);
- Htmlstring.Replace("<", "");
- Htmlstring = Regex.Replace(Htmlstring, @"”", "", RegexOptions.IgnoreCase);
- Htmlstring.Replace(">", "");
- Htmlstring.Replace("\r\n", "");
- Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();
- return Htmlstring;
- }
- #endregion
- }
- }
|