asp string replace in recordset
hi!
im using this example from the w3c website...
Code:
<%
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
Code:
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!
PHP Code:
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...
hmmm im getting an error...
Microsoft VBScript runtime error '800a01c3'
Object not a collection
thanks for your help so far!
Here you go, tested and works:
PHP Code:
<%
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.
Last edited by Ubik; 01-20-2006 at 02:16 PM .
hi ubik! that was great!
sorry for the delayed reply...
its working great btw!
how would you be able to make it replace the words with *'s say, with the correct length of the word..
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
thanks greatly!
Change:
strCleanText = replace(strCleanText, trim(strSwearWord), "[BEEP]")
To:
PHP Code:
strCleanText = replace ( strCleanText , trim ( strSwearWord ), String ( len ( trim ( strSwearWord )), "*" ))
(tested, works)
thats fantastic! thankyou!
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks