The Censor function removes disallowed words from a string. Censored words are
kept in a text file. The format of the text file is simple: one restricted word
per line. The system will read the restricted words and replace all of those
words with xxx's the same length as the removed word in the string. There is no
limit to the amount of words that can be restricted.
string = Censor(uncensoredstring)
ASP Source Code:
' contents of c:\dirtywords.txt:
' phrase to check
a = "Can you believe that word1 guy over there? What a word2 that guy is."
response.write Censor( a )
' Can you believe that xxxxx guy over there?
' What a xxxxx that guy is.
Private Function Censor(byVal string)
Const WordList = "C:\dirtywords.txt"
Dim objFSO, objFile, tmp, item, word, a, b, x, y, i, c, j
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile( WordList )
tmp = split( objFile.ReadAll(), vbCrLf )
Set objFile = Nothing
Set objFSO = Nothing
x = split( string, " " )
for i = 0 to ubound(x)
a = x(i)
For each item in tmp
b = item
if cstr(trim(lcase(a))) = _
c = Len(a)
a = "
for j = 1 to c
a = a & "x"
a = a & ""
x(i) = a
Censor = Join( x, " " )