|
-
Oct 28th, 2004, 10:37 PM
#1
Thread Starter
Frenzied Member
Bad word filter
Does anyone know how to make a bad word filter that is case insinsitive? I have been google-ing all night and found some different examples of word filters (some better than others), but none that are case insensitive without changing the case of the text. I basically want to do what this forum does without having to add diferent cases to the words. Like lets say crap is a bad word, I want it to find Crap, crAP, CRAP, etc, but not crape. I know it can be done with regular expressions (which I think this board uses) but I don't know regular expressions worth crap. Here is the code I have now, but it is case sensative:
VB Code:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim xmlDocPath As String = Server.MapPath("bad_words.xml")
Dim xmlReader As XmlTextReader = New XmlTextReader(xmlDocPath)
While (xmlReader.Read())
If xmlReader.NodeType = XmlNodeType.Text Then
alWordList.Add(xmlReader.Value)
Trace.Write("Added: " & xmlReader.Value)
End If
End While
xmlReader.Close()
End Sub
Public Function CheckString(ByVal InputString As String) As String
Dim r As Regex
Dim element As String
Dim output As String
Trace.Write("Checking " & InputString)
For Each element In alWordList
r = New Regex("\b" & element)
Trace.Write("Checking: " & element)
InputString = r.Replace(InputString, "****")
Next
Trace.Write("Returning " & InputString)
Return InputString
End Function
XML
<words>
<word>badword</word>
<word>reallybadword</word>
<word>omgyouusedthisword</word>
</words>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|