Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 help with word filter
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

RaiderUK
Average Member

United Kingdom
577 Posts

Posted - 21 April 2001 :  21:19:56  Show Profile  Send RaiderUK a Yahoo! Message
was just building a quick word filter but its annoying me now, it will only replace the last word. can anyone help?

<%
Dim strString, strBadWords, strNew, i, strWrd
strString = "This is a bad word: worda and this: wordd and wordc"
strBadWords = "worda|wordb|wordc|wordd"
strBadWords = split(strBadWords, "|")
for each i in strBadWords
strWrd = cStr(i)
strNew = Replace(strString, strWrd, "****")
strNew = cStr(strNew)
next
%>



Marino
Starting Member

Canary Islands
42 Posts

Posted - 22 April 2001 :  00:26:47  Show Profile  Send Marino an ICQ Message
quote:

was just building a quick word filter but its annoying me now, it will only replace the last word. can anyone help?

<%
Dim strString, strBadWords, strNew, i, strWrd
strString = "This is a bad word: worda and this: wordd and wordc"
strBadWords = "worda|wordb|wordc|wordd"
strBadWords = split(strBadWords, "|")
strNew = cStr(strString)
for each i in strBadWords
strWrd = cStr(i)
strNew = Replace(strNew, strWrd, "****")
strNew = cStr(strNew)
next
%>







Marino
Go to Top of Page

RaiderUK
Average Member

United Kingdom
577 Posts

Posted - 22 April 2001 :  07:28:47  Show Profile  Send RaiderUK a Yahoo! Message
i have tried it like that but still the same problem, any ideas?

Go to Top of Page

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 22 April 2001 :  07:44:34  Show Profile  Visit HuwR's Homepage
try this


for i = 0 to ubound(strBadWords )
fString = Replace(fString, strBadWords (i), string(len(strBadWords(i)),"*"), 1,-1,1)
next


Go to Top of Page

RaiderUK
Average Member

United Kingdom
577 Posts

Posted - 22 April 2001 :  09:22:25  Show Profile  Send RaiderUK a Yahoo! Message
thanks alot, works brilliant now.

why wouldnt it work before? it looked right.

Go to Top of Page

Marino
Starting Member

Canary Islands
42 Posts

Posted - 23 April 2001 :  10:11:32  Show Profile  Send Marino an ICQ Message
The code I wrote works for me, in every iteration strNew has:

This is a bad word: **** and this: wordd and wordc
This is a bad word: **** and this: wordd and wordc
This is a bad word: **** and this: wordd and ****
This is a bad word: **** and this: **** and ****


The code in your post had the problem that you are checking for bad words in strString, while doing changes in strNew, so in first iteration you have in strNew the content of strString with first bad word changed and strString unchanged. In second iteration, you change the second bad word in strString, but strString was unchanged, so it still had the first bad word (well, actually in second iteration there are no changes, as there aren't "wordb" bad words in strString" ). and so on.

So at the end, you finish with strNew having StrString changed only the last iteration.

Iteration 1 (worda)
strString = "This is a bad word: worda and this: wordd and wordc"
strNew = "This is a bad word: **** and this: wordd and wordc"
Iteration 2 (wordb)
strString = "This is a bad word: worda and this: wordd and wordc"
strNew = "This is a bad word: worda and this: wordd and wordc"
Iteration 3 (wordc)
strString = "This is a bad word: worda and this: wordd and wordc"
strNew = "This is a bad word: worda and this: wordd and ****"
Iteration 4 (wordd)
strString = "This is a bad word: worda and this: wordd and wordc"
strNew = "This is a bad word: worda and this: **** and wordc"




Marino


Edited by - marino on 23 April 2001 10:14:47
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.3 seconds. Powered By: Snitz Forums 2000 Version 3.4.07