点击回首页
我的浏览记录 | | 帮助?
当前位置:

源码截图

源码目录树

当前路径:InsApp/WebSearch/Getword.cs     using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using InsApp.log4;

//该源码下载自www.51aspx.com(51aspx.com)

namespace InsApp.WebSearch
{
    /// <summary>
    /// string Check_url(正则表达式,内容)返回string    return m.Groups[1].ToString();
    /// Check_ChineseCode(字符串)检查输入的网址中是否包含汉字,如果包含汉字,进行编码{1,9}1-9个汉字匹配
    /// string Check_url_All(正则表达式,内容)  GetAllInfo += m.Value;
    /// string NoHTML(string Htmlstring)        去除<js>
    /// </summary>
    

    public class Getword
    {
        InsApp.word.CreateCode Ck_CheckNull = new InsApp.word.CreateCode();
        Type type = System.Reflection.MethodBase.GetCurrentMethod().DeclaringType;

        #region 检查输入的网址中是否包含汉字,如果包含汉字,进行编码{1,9}1-9个汉字匹配
        /// <summary>
        /// 检查输入的网址中是否包含汉字,如果包含汉字,进行编码{1,9}1-9个汉字匹配
        /// </summary>
        /// <param name="userInput">用户输入的内容,也就是要检查的内容</param>
        /// <returns></returns>
        public string Check_ChineseCode(string userInput)
        {
            string RegStr = "[\u4e00-\u9fa5]{1,9}";
            Regex rgx = new Regex(RegStr);
            Regex r = new Regex(RegStr);
            Match m = r.Match(userInput);
            if (m.Success == false)
            {
                return userInput;
            }
            while (m.Success)
            {
                ///		如果匹配汉字的话,将汉字编码
                userInput = rgx.Replace(userInput, System.Web.HttpUtility.UrlEncode(m.Value.ToString().Trim(), System.Text.Encoding.GetEncoding("GB2312")));
                m = m.NextMatch();
            }
            return userInput;
        }
        #endregion

        #region 返回匹配的整个内容
        /// <summary>
        /// 函数功能:获得用户输入的值
        /// 首先判断是否为空值
        /// 根据Session[变量],检查输入的正则匹配
        /// 返回信息
        /// userInput	用户输入的值或者  正则表达式
        /// WebText		读取的网页信息,存储在Session中,不能为空;
        /// IsGood		是否匹配	付给LBL_err.text
        /// return_str	通过正则匹配,返回的信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public string Check_url_All(string userInput, string WebText)
        {
            string GetAllInfo = string.Empty;
            try
            {
                if (userInput == null || userInput == "")
                {
                    return "请输入匹配的正则表达式";
                }
                if (WebText == null || WebText == "")
                {
                    return "请重新读取网页内容。";
                }
                MatchCollection mc = Regex.Matches(WebText, userInput, RegexOptions.IgnoreCase);

                foreach (Match m in mc)
                {
                    GetAllInfo += m.Value;
                }
                return GetAllInfo;
            }
            catch (Exception ex)
            {
                LogUtil.FATAL(type, ex.Message);
                return "无法匹配内容";
            }

        }
        #endregion

        #region 去除HTML标记
        /// <summary>
        /// 去除HTML标记
        /// </summary>
        /// <param name="Htmlstring">包括HTML的源码 </param>
        /// <returns>已经去除后的文字</returns>
        public 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);*/
            //      add new 2006-12-30
            //Htmlstring = Regex.Replace(Htmlstring, @"<.*?>", "", RegexOptions.IgnoreCase);//      清除所有标签
            Htmlstring = Regex.Replace(Htmlstring, @"<script.*>[\s\S]*?</script>", "", RegexOptions.IgnoreCase);

            //Htmlstring.Replace("<", "");
            // Htmlstring.Replace(">", "");
            //Htmlstring.Replace("\r\n", "");
            //Htmlstring = HttpContext.Current.Server.HtmlEncode(Htmlstring).Trim();

            return Htmlstring;
        }
        #endregion

    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途) 企业QQ:4000410510
地址:北京市海淀区中关村鼎好大厦A座二层 邮编:100080
Room A-801,Dinghao Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2015. 京ICP备09089570号 | 京公网安备11010702000869号
在线客服
分享该页面
关闭侧边栏