Simple Text Replace - For Swearing Validation/Custom Tags etc.

In the development of a forum program in ASP, I found it neccesary to implement several features, if the project was the match the forerunners of the day.

I figured that using this bit of code, I could acheive all of them. This code works to replace anything a user types in a specific feild of a new record with custom text or HTML you wish to appear.

Thats all there is to it. PLEASE NOTE: The file in this zip archive contains the results of my swearing validation, and as such, contains a LOT of swears. Be warned before opening :)

Hope this is of some use!

Joe Utichi
www.dreamcastuk.net
www.ps2-4u.com

NOTE: IF YOU ARE USING THIS CODE IN A REPEAT REGION, MAKE SURE EVERYTHING IS NESTED IN THE REGION OR IT WILL NOT FUNCTION CORRECTLY.

Number 1. Open the code with the following tags:

 <%
MessageContent = Recordset.Fields.Item("YourField").value

Where "Recordset" is the name of the recordset being used and "YourField" is the name of the field you wish the code to work for.

Number 2. Use this template for the lines of code you wish to replace:

MessageContent = Replace(MessageContent,"TEXTTOREPLACE","REPLACEMENTTEXT")

Where TEXTTOREPLACE is the text the user will enter to be transformed and REPLACEMENTTEXT is the text that will appear in its place. For example, you may wish to have certain swear words replaced with asterisks, or certain smilies replaced with image equivalents. A word of warning, if you want to use HTML code as the replacee or replacor (new words?) DO NOT include " signs. HTML will function pretty much all the time without them, and the code will not work if you use them.

Number 3. End this block with a standard close:

%>

Number 4. Place this code on your page where you wish the replaced feild to appear:

<%= MessageContent %>

Thats all there is to it. PLEASE NOTE: The file in this zip archive contains the results of my swearing validation, and as such, contains a LOT of swears. Be warned before opening :)

Hope this is of some use!

Joe Utichi
www.dreamcastuk.net
www.ps2-4u.com

Below is Swearing validation:

THIS IS THE BLOCK FOR WHAT YOU WISH TO REPLACE

 <%
MessageContent = Recordset.Fields.Item("YourField").value
MessageContent = Replace(MessageContent,"fuck","****")
MessageContent = Replace(MessageContent,"Fuck","****")
MessageContent = Replace(MessageContent,"FUCK","****")
MessageContent = Replace(MessageContent,"shit","****")
MessageContent = Replace(MessageContent,"[/I]","")
MessageContent = Replace(MessageContent,"Shit","****")
MessageContent = Replace(MessageContent,"SHIT","****")
MessageContent = Replace(MessageContent,"cunt","****")
MessageContent = Replace(MessageContent,"Cunt","****")
MessageContent = Replace(MessageContent,"CUNT","****")
MessageContent = Replace(MessageContent,"cock","****")
MessageContent = Replace(MessageContent,"Cock","****")
MessageContent = Replace(MessageContent,"COCK","****")
MessageContent = Replace(MessageContent,"wanker","******")
MessageContent = Replace(MessageContent,"Wanker","******")
MessageContent = Replace(MessageContent,"WANKER","******")
MessageContent = Replace(MessageContent,"twat","****")
MessageContent = Replace(MessageContent,"Twat","****")
MessageContent = Replace(MessageContent,"TWAT","****")
MessageContent = Replace(MessageContent,"tosser","******")
MessageContent = Replace(MessageContent,"Tosser","******")
MessageContent = Replace(MessageContent,"TOSSER","******")
MessageContent = Replace(MessageContent,"piss","****")
MessageContent = Replace(MessageContent,"Piss","****")
MessageContent = Replace(MessageContent,"PISS","****")
MessageContent = Replace(MessageContent,"pussy","*****")
MessageContent = Replace(MessageContent,"Pussy","*****")
MessageContent = Replace(MessageContent,"PUSSY","*****")
MessageContent = Replace(MessageContent,"whore","*****")
MessageContent = Replace(MessageContent,"Whore","*****")
MessageContent = Replace(MessageContent,"WHORE","*****")
MessageContent = Replace(MessageContent,"slut","****")
MessageContent = Replace(MessageContent,"Slut","****")
MessageContent = Replace(MessageContent,"SLUT","****")
MessageContent = Replace(MessageContent,"asshole","*******")
MessageContent = Replace(MessageContent,"Asshole","*******")
MessageContent = Replace(MessageContent,"ASSHOLE","*******")
MessageContent = Replace(MessageContent,"bitch","*****")
MessageContent = Replace(MessageContent,"Bitch","*****")
MessageContent = Replace(MessageContent,"BITCH","*****")
MessageContent = Replace(MessageContent,"blowjob","*******")
MessageContent = Replace(MessageContent,"Blowjob","*******")
MessageContent = Replace(MessageContent,"BLOWJOB","*******")
MessageContent = Replace(MessageContent,"handjob","*******")
MessageContent = Replace(MessageContent,"Handjob","*******")
MessageContent = Replace(MessageContent,"HANDJOB","*******")
MessageContent = Replace(MessageContent,"jackass","*******")
MessageContent = Replace(MessageContent,"Jackass","*******")
MessageContent = Replace(MessageContent,"JACKASS","*******")
MessageContent = Replace(MessageContent,"faggot","******")
MessageContent = Replace(MessageContent,"Faggot","******")
MessageContent = Replace(MessageContent,"FAGGOT","******")
MessageContent = Replace(MessageContent,"queer","*****")
MessageContent = Replace(MessageContent,"Queer","*****")
MessageContent = Replace(MessageContent,"QUEER","*****")
MessageContent = Replace(MessageContent,"pimp","****")
MessageContent = Replace(MessageContent,"Pimp","****")
MessageContent = Replace(MessageContent,"PIMP","****")
MessageContent = Replace(MessageContent,"fag","***")
MessageContent = Replace(MessageContent,"Fag","***")
MessageContent = Replace(MessageContent,"FAG","***")
MessageContent = Replace(MessageContent,"assmunch","********")
MessageContent = Replace(MessageContent,"Assmunch","********")
MessageContent = Replace(MessageContent,"ASSMUNCH","********")
MessageContent = Replace(MessageContent,"buttmunch","*********")
MessageContent = Replace(MessageContent,"Buttmunch","*********")
MessageContent = Replace(MessageContent,"BUTTMUNCH","*********")
MessageContent = Replace(MessageContent,"ass","***")
MessageContent = Replace(MessageContent,"Ass","***")
MessageContent = Replace(MessageContent,"ASS","***")
MessageContent = Replace(MessageContent,"arse","****")
MessageContent = Replace(MessageContent,"Arse","****")
MessageContent = Replace(MessageContent,"ARSE","****")
MessageContent = Replace(MessageContent,vbcrlf,"
") %>

THIS NEXT TAG IS WHERE THE CODE WILL GO:

 <%= MessageContent %>

Comments

Another way

July 24, 2001 by George Petrov

Another way of doing massive string change is using regular expressions (also available in VBscript 5+), Example:

 MessageContent = Recordset.Fields.Item("YourField").value
 Set regEx = New RegExp     ' Create regular expression.
 regEx.Pattern = "asshole|pussy|piss" ' Set pattern.
 regEx.IgnoreCase = True    ' Make case insensitive.
 regEx.Global = True       ' Set global applicability.   
 MessageContent = regEx.Replace(MessageContent, "****") ' Make replacement.

You should add your own words to the pattern, divided my |
Also note thet this is a case insensitive approach.

how do you do it for different fields?

February 4, 2002 by penar samu

in my forum script i have different field for messages and different for replies but both appear in the same page (I use DUforum). How can I do this in this case?

 

 

 

Microsoft VBScript runtime error '800a01c2'

May 4, 2002 by Leon Bedro
Microsoft VBScript runtime error '800a01c2'

Wrong number of arguments or invalid property assignment: 'Replace'

RE: Microsoft VBScript runtime error '800a01c2'

May 4, 2002 by Leon Bedro

Sorry forget to tell you!

I get this Error and I want to know how to fix it.

Here is some of the code:

                  <%
While ((Repeat1__numRows <> 0) AND (NOT rec.EOF))
%>
                   <%
        MessageContent = Replace(rec.Fields.Item("Kommentar").value)
      MessageContent = Replace(MessageContent,"TEXTTOREPLACE","REPLACEMENTTEXT")
     %>
     
                  <table width="100%" border="0" cellspacing="2" cellpadding="1" bgcolor="#FFFFFF">
                    <tr>
                      <td height="2" valign="middle" align="left"><i>Av</i>: <b><%=(rec.Fields.Item("Namn").Value)%></b> <a href="mailto:<%=(rec.Fields.Item("Email").Value)%>"><img src="../images/email_button.gif" width="16" height="16" border="0" align="texttop"></a>
                        | <span class="date"><%= DoDateTime((rec.Fields.Item("datum").Value), 1, 1053) %></span> </td>
                    </tr>
                    <tr>
                      <%If (Repeat1__numRows Mod 2) Then%>
                      <td style="background-color:#FFE1F0">
                        <%Else%>
                      <td style="background-color:#F5F5F5">
                        <%End If%>
                        <img src="../images/pratbubbla.gif" width="15" height="10">
                        <%=MessageContent%></td>
                    </tr>
                    <tr>
                      <td>
                        <div align="right"><i>Betyg p&aring; hemsidan: <font color="#990033"><b><font color="#990000"><%=(rec.Fields.Item("Betyg").Value)%></font></b></font></i></div>
                      </td>
                    </tr>
                  </table>
                  <br>
                  <%
  repeat1__index="Repeat1__index"+1
  repeat1__numrows="Repeat1__numRows"-1
  rec.MoveNext()
Wend
%>

You must me logged in to write a comment.