1 Temmuz 2007 Pazar

Replace Bad (or profane) Words from a String

Dim sMyString
sMyString = ReplaceBadWords("this is a rubbish crap bad word filter")
response.write sMyString

Function ReplaceBadWords(InputComments)
Dim badChars, newChars, sLength, sAttachtoEnd, x, i
'create an array of bad words that should be filtered
badChars = array("rubbish", "crap", "shit")
newChars = InputComments
'loop through our array of bad words
For i = 0 to uBound(badChars)
'get the length of the bad word
sLength=Len(badChars(i))
'we are going to keep the first letter of the bad word and replace all the other
'letters with *, so we need to find out how many * to use
For x=1 to sLength-1
sAttachtoEnd=sAttachtoEnd & "*"
Next
'replace any occurences of the bad word with the first letter of it and the
'rest of the letters replace with *
newChars = Replace(newChars, badChars(i), Left(badChars(i),1) & sAttachtoEnd)
sAttachtoEnd=""
Next
ReplaceBadWords = newChars
End function


0 Comments: