Rather than confine yourself to periodically searching the Messageboards or Guestbooks on your site for offensive language, why not have these posts automatically censored (if needed) when posted? The following code provides a function, CensorStr with the following definition:
Function CensorStr(NaughtyString) |
CensorStr takes one parameter, NaughtyString, which is the string you want to censor. The function returns a censored version of NaughtyString. The code for CensorStr follows:
Function CensorStr(NaughtyString)
'this array defines the words to look for and what to
'replace the word with if found.
ExpletivesBAD = Array("cat","chicken","dog","horse","pig")
ExpletivesCEN = Array("c*t","c*****n","d*g","h**se","#!#")
TotalExpletives = ubound(expletivesBAD)
'This for loop loops through all of the expletives,
'replacing them with the appropriate string if they exist
'in NaughtyString
for i = 0 to TotalExpletives
CENSOR = InStr(1, NaughtyString, ExpletivesBAD(i), 1)
if CInt(CENSOR) > 0 then
'Note that two versions of the expletive are searched. We
'use these two variations to we can be sure that we do
'not catch a nonexpletive accidentally. For example, if
'we want to censor "hell," we want to make sure we do not
'censor "hello"
NaughtyString = replace(NaughtyString," " & _
ExpletivesBAD(i),ExpletivesCEN(i),1,-1,1)
NaughtyString = replace(NaughtyString,ExpletivesBAD(i) & _
" ",ExpletivesCEN(i),1,-1,1)
end if
next
CensorStr = NaughtyString
End Function
|
You can try out the above code. In the text box below, enter a string, and it will be censored. Note that the only words that are censored are: cat, chicken, dog, horse, and pig; they will be censored with c*t, c*****n, d*g, h**se, and #!#, respectively.
discuss this topic to forum