用asp.net如何做过滤脏话问题
在论坛上在发表的时候评论的时候,输入的内容去掉用户输入的诸如‘易做图|易做图|易做图妈|靠|易做图’等等这些文本,如何更好的用asp.net制作一个程序过滤掉这些文字?谢谢,有整个例子是最好的,谢谢各位大虾的帮助! --------------------编程问答-------------------- Regex.Replace("易做图|易做图|易做图妈|靠|易做图文本","易做图|易做图|易做图妈|靠|易做图","*"); --------------------编程问答--------------------正解,呵呵 --------------------编程问答--------------------
........................................................... --------------------编程问答--------------------
大哥你点儿啥。。。 --------------------编程问答-------------------- LZ骨骼一下 fanhexie.tk 偶自己做了个 遍历词库
Imports System.IO--------------------编程问答-------------------- 在后台设置过滤字符
Partial Class wordtool_dohx
Inherits System.Web.UI.Page
Protected Sub form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles form1.Load
Dim strRtnWord As String
Dim strWord As String = Request.Form("str")
Dim strFilter As String = Request.Form("strFilter")
'Dim strWord As String = "今天我们去易做图哈哈哈 反日吧。。。。。个哦个哦个哦过"
'Dim strFilter As String = "/*/"
If Not IsPostBack Then
strRtnWord = doFilterword(strWord, strFilter)
Response.Write(strRtnWord)
Response.End()
End If
End Sub
Public Function doFilterword(ByVal i_strWord As String, ByVal i_strFilter As String) As String
Dim strTemp As String = ""
Dim strArr As String = ""
Dim strFilter As String = ""
strTemp = i_strWord
For i As Integer = 0 To CType(Application("arrList"), ArrayList).Count - 1
strArr = CType(Application("arrList"), ArrayList)(i).ToString
strFilter = ""
For j As Integer = 0 To strArr.Length - 1
strFilter = strFilter & strArr(j) & i_strFilter
Next
strTemp = strTemp.Replace(strArr, strFilter)
Next
Return strTemp
End Function
End Class
<%@ Application Language="VB" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application startup
loadWordData()
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when an unhandled error occurs
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a new session is started
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
End Sub
Public Sub loadWordData()
Dim arrList As ArrayList
arrList = New ArrayList
Dim sr As StreamReader = New StreamReader(Server.MapPath("~/") + "\word.txt")
Do While sr.Peek() >= 0
arrList.Add(Trim(sr.ReadLine()))
Loop
sr.Close()
Application("arrList") = arrList
End Sub
</script>
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;
}
--------------------编程问答--------------------
。。。。。。。。。。。。。。。。。 --------------------编程问答--------------------
看来csdn没这么先进的过滤系统。 --------------------编程问答--------------------
哥們,你厲害,這都發現了 --------------------编程问答--------------------
我也试试看 --------------------编程问答-------------------- 哥们儿你太猛了 顶你 --------------------编程问答-------------------- 做个词库,提交时根据词库过滤 --------------------编程问答-------------------- --------------------编程问答-------------------- Regex.Replace --------------------编程问答--------------------
这个应该再改进一下,因为这种情况是没法过滤“我易做图操”这种情况的(这种情况过滤后还是“易做图”),所以用个循环
--------------------编程问答--------------------
while(Regex.Match(易做图|易做图|易做图妈|靠|易做图文本","易做图|易做图|易做图妈|靠|易做图").Success)
{
Regex.Replace("易做图|易做图|易做图妈|靠|易做图文本","易做图|易做图|易做图妈|靠|易做图","*");
}
--------------------编程问答-------------------- 正则表达式匹配并替换. --------------------编程问答--------------------
厉害~~~ 顶~~ --------------------编程问答-------------------- --------------------编程问答-------------------- 哈哈哈 --------------------编程问答--------------------
我就玩3C! --------------------编程问答--------------------
神 来了 --------------------编程问答--------------------
while(Regex.Match(易做图|易做图|易做图妈|靠|易做图文本","易做图|易做图|易做图妈|靠|易做图").Success)
{
Regex.Replace("易做图|易做图|易做图妈|靠|易做图文本","易做图|易做图|易做图妈|靠|易做图","*");
}
先判断是不是匹配,然后替换 --------------------编程问答-------------------- --------------------编程问答-------------------- lz 可以参考上图的方法,保证你的系统绝对安全,绝对不会出现“脏话” --------------------编程问答-------------------- 用C#的话,.net framework 5.0将自带脏话过滤函数:
System.Text.ZhangHua.Filter(); --------------------编程问答-------------------- 关注!!! --------------------编程问答-------------------- 自己新建一个脏话的表,然后时刻的进行脏话的更新,如果数据不多,就缓存在内存中,如果数据 量很大,你可以缓存热门的脏话用语,然后进行replace,就可以了啊。
补充:.NET技术 , ASP.NET