当用户发表言论的时候,我们把脏字替换成* ,要如何做?各位详细讲讲,最好给我个例子 邮箱:[email protected]

解决方案 »

  1.   

    http://www.cnblogs.com/xingd/archive/2008/01/31/1060425.html
      

  2.   

    string resultString = null;
    try {
    resultString = Regex.Replace("frgr脏字1feagreg脏字2grsgr", @"脏字1|脏字2|脏字3", @"xxxxx");
    } catch (ArgumentException ex) {
    // Syntax error in the regular expression
    }
      

  3.   

    可以把你以为得非法字放到一个数据表中~~    protected void Page_Load(object sender, EventArgs e){
            //判断给定字符串内是否含有敏感词,true代表有,false代表没有
            Page.Request.ContentEncoding = Encoding.GetEncoding("utf-8");
            Page.Response.ContentEncoding = Encoding.GetEncoding("utf-8");
            Response.ContentType = "application/json";
            string strValue=Request["text"];//这是你的内容
            if (strValue == null) strValue = "";
            strValue=Microsoft.JScript.GlobalObject.unescape(strValue);
            strValue = ;//过滤HTML(把你认为的非法字读出)
            bool bResult=;//判断是否该替换
            Response.Write("{result:'" + bResult.ToString().ToLower() + "'}");
        }
      

  4.   

    在网站后台设置过滤字符
    void Application_BeginRequest(object sender, EventArgs e)
    {
         for (int i=0; i < Request.Form.Count;i++)
         {
             if (Request.Form[i].ToString() == "__VIEWSTATE") continue;
             if (IsM(Request.Form[i].ToString()))
             {
                  Response.Write("您提交的内容中含有非法字符.");
                  Response.End();
              }      } 
    }
    protected bool IsM(string InText)
    {
        string word = @"";
        if (InText == null)
            return false;
        if (Regex.IsMatch(InText,word))
             return true;
         return false;