StrCensor Function:
Removes disallowed words from a string.
Description:
The StrCensor 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.
Syntax:
string = StrCensor(uncensoredstring, filepath)
Details:
contents of c:\dirtywords.txt:
word1 word2
Example:
<%
dim a, file
'--- phrase to check a = "Can you believe that word1 guy over there? What a word2 that guy is." file = "c:\dirtywords.txt" response.write StrCensor( a, file )
'--- returns: '--- Can you believe that xxxxx guy over there? What a xxxxx that guy is.
%>
ASP Source Code:
<%
Private Function StrCensor(byVal string, byVal filepath) Dim objFSO, objFile, tmp, item, word, a, b, x, y, i, c, j Set objFSO = Server.CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile( filepath ) tmp = split( objFile.ReadAll(), vbCrLf ) objFile.Close 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))) = _ cstr(Trim(lcase(b))) then c = Len(a) a = "" for j = 1 to c a = a & "x" next a = a & "" exit for end if next x(i) = a next StrCensor = Join( x, " " ) End Function
%>
|