ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Try It Free
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old September 26th, 2003, 07:49 AM
help-me-pls help-me-pls is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 8 help-me-pls User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Angry replace rude names in string with anonymous

Hi

I'm going to make a database of rude words, that i do not want users to name themselves when they use my scoreboard. I need my asp to scan their string and if a word from the database appears replace the entire string with anonymous.

I have some code which was designed to astrisk out all but the first and last letter of any appearing rude word

eg: d**n this b****y game
or godd**nit

i have changed this to just replace each word to anonymous, but cant get it to the stage above, can any one help? My code so far is below.

Code:
<%
'pull our text from the form field, and parse it
Response.Write fnParseSwear(Request.Form("formSwear"))
'this function parses a string, filtering out the swear words defined by yourself
Function fnParseSwear(strSwear)
'Declare our variable
	Dim rex, match, matches
'Create an instance of the regexp object
	Set rex = New regexp
'the almighty regexp pattern, put your swear words here, no spaces, seperated by a vertical
'break/bar ( | )
	rex.Pattern = "heck|darn|damn|bloody"
'global determines whether we search the whole string, or just
'be satisfied w/ the first hit we come across.
	rex.Global = True
'ignorecase, self explanatory
	rex.IgnoreCase = True
'execute the regexp on our text string
    Set matches = rex.Execute(strSwear)
'go thru the matches (swear words), and replace them 
    For Each match in matches
        strSwear = Replace(strSwear, match, fnChange(match))
    Next
'set our function equal to our parsed string...
    fnParseSwear = strSwear
'Clean up
	Set rex = Nothing
	
End Function

'this function replaces the swear word w/ asterisks
Function fnChange(strSwearWord)
'replace word with anonymous
    fnChange = Replace(strSwearWord, (strSwearWord), "anonymous")
End Function
%>


cheers

Reply With Quote
  #2  
Old September 30th, 2003, 10:11 PM
pda8333 pda8333 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 216 pda8333 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 8 h 6 m 31 sec
Reputation Power: 5
hi help-me-pls,

i have a similar function as yours but the style of coding is different. I use mine for scanning rude words in my Guestbook. What mine does is if it detects a rude word, it will give an error message instead of replacing to 'anonymous'.

My list of rude words is inside a table in a MS Access called BanWords instead of listing all in your code.

Code:
Set con = Server.CreateObject("ADODB.Connection")
con.Open SetConnectionString

Dim Comments, tmpComments, TotaltmpComments

Comments = replace(trim(request.form("Remarks")),"'","''")
Comments = LCase(Comments)

Do While InStr(1, Comments, "  ")
   Comments = Replace(Comments, "  ", " ")
Loop

tmpComments = Split(Comments, " ", -1, VBTextCompare)
TotaltmpComments = (ubound(tmpComments) - lbound(tmpComments) + 1)
Counter = 0
Do Until Counter = TotaltmpComments
  tmpComments(Counter) = Trim(tmpComments(Counter))
  BADWORDSSQL = "Select BanWord From BanWords Where BanWord ='" & tmpComments(Counter) & ""
  Set rsBanWords = Con.Execute(BADWORDSSQL)
     if not rsBanWords.eof then
        ' i used my error msg here, but you can
        ' use your fnChange function here instead.
     end if
  Counter = Counter + 1
Loop

But this has a small limitation. The rude word must be a stand-alone word first. For example if you write 'darned' and if your database rude word is 'darn', then it can't work.

If anybody out there can help me out with this, thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > replace rude names in string with anonymous


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway