Click to See Complete Forum and Search --> : asp string replace in recordset


deep-wood
01-09-2006, 09:41 AM
hi!

im using this example from the w3c website...

<%
dim txt
txt="This is a beautiful day!"
response.write(Replace(txt,"beautiful","horrible"))
%>

it works, however, i need to adapt it, and not sure how. basicly, i want to make like a swear word filter for a guestbook....
so lets say txt = recordset("post") - and i did response.write(Replace(txt,"naughty_word","_a_good_word"))
thats fine. however, there are many more words then this....how would i adapt this code to do more replaces in that string. copying the replace line just writes the details again...

thanks all!

Ubik
01-09-2006, 12:15 PM
strTextToBeCleaned = recordset("post")
strCleanText = strTextToBeCleaned
strSwearWordList="beep, boop, bleep, bop, sheboing, ppppffft, bang"
astrSwearWordList=split(astrSwearWordList)
For Each strSwearWord In aSwearWords
strCleanText = replace(strCleanText, strSwearWord, "[BEEP]")
Next


/haven't tested this...

deep-wood
01-09-2006, 07:25 PM
hmmm im getting an error...

Microsoft VBScript runtime error '800a01c3'

Object not a collection

thanks for your help so far!

Ubik
01-10-2006, 11:40 AM
Here you go, tested and works:

<%
strTextToBeCleaned = "bleep you, you mother boper"
strCleanText = strTextToBeCleaned
strSwearWordList="beep, boop, bleep, bop, sheboing, ppppffft, bang"
astrSwearWordList=split(strSwearWordList, ",")
response.write "<p><ul>"
For Each strSwearWord In astrSwearWordList
strCleanText = replace(strCleanText, trim(strSwearWord), "[BEEP]")
response.write "<li>Checking '"&strSwearWord&"' - Changed to: "&strCleanText&"</li>"
Next
response.write "</ul></p>"
response.write "<p>"&strCleanText&"</p>"
%>

Sorry, I has some variables out of place before.

deep-wood
01-19-2006, 10:42 PM
hi ubik! that was great! :D

sorry for the delayed reply...

its working great btw! :D:D

how would you be able to make it replace the words with *'s say, with the correct length of the word.. :confused:

say, the word SHABBA - 6 letters long, how can i make ****** - give a bit of a tease...lol, allways fun to guess what the word is lol :rolleyes:

thanks greatly!

Ubik
01-20-2006, 03:19 PM
Change:
strCleanText = replace(strCleanText, trim(strSwearWord), "[BEEP]")

To:

strCleanText = replace(strCleanText, trim(strSwearWord), String(len(trim(strSwearWord)), "*"))


(tested, works)

deep-wood
01-21-2006, 01:02 PM
thats fantastic! thankyou!