Hello -
This code was snagged by me from the Internet and altered. Its purpose is
to check for swear words. It works the way it currently is, but I need it to
be more generic -- i.e., I don't want it to refer to TextBox1 or Label1
directly; I want to be able to plug in the name of any textbox into
CheckString(TextBox1.Text), instead of just a specific textbox. [I have many
textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string)
Dim alWordList as New ArrayList
Dim origtext as String
origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()
Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
InputString = r.Replace(InputString, "****")
Next
TextBox1.Text = InputString
If origtext <> TextBox1.Text Then
Label1.Text = "Funky words, please replace."
Else
Label1.Text = "Okay." 'This is just included for testing
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1.Text)
End Sub
Any suggestions will be greatly appreciated!
--
Sandy 8 1379
Hi Sandy,
You can try
Public Sub CheckString(txtBox As TextBox, lbl As Label)
Dim alWordList as New ArrayList
Dim inputstring as string = txtBox.Text
Dim origtext as String = inputstring
dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()
Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
inputString = r.Replace(inputString, "****")
Next
txtBox.Text = inputString
If Not origtext.Equals(inputString) Then
lbl.Text = "Funky words, please replace."
Else
lbl.Text = "Okay." 'This is just included for testing
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1, Label1)
End Sub
"Sandy" wrote: Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
Hi Sandy,
You can try
Public Sub CheckString(txtBox As TextBox, lbl As Label)
Dim alWordList as New ArrayList
Dim inputstring as string = txtBox.Text
Dim origtext as String = inputstring
dim xmlDocPath as string = server.mappath("bad_words2.xml")
dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath)
While (xmlReader.Read())
if xmlReader.Nodetype=xmlNodeType.Text then
alWordList.Add(xmlReader.Value)
End If
End While
xmlReader.Close()
Dim r as Regex
dim element as string
dim output as string
For Each element in alWordList
r = New Regex("\b" & element)
inputString = r.Replace(inputString, "****")
Next
txtBox.Text = inputString
If Not origtext.Equals(inputString) Then
lbl.Text = "Funky words, please replace."
Else
lbl.Text = "Okay." 'This is just included for testing
End If
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
CheckString(TextBox1, Label1)
End Sub
"Sandy" wrote: Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
You could achieve this by e.g. creating a new class with a static
method called
public static bool CheckString( string input, string censoredString )
that returns a bool indicating whether it had to censor the string.
The censored string is written into the second string reference you
pass.
Since I am not familiar with VB, here is the C# for that.
public class SwearWordChecker{
public static string CheckString( string input, string censoredString
){
censoredString = input;
// do your thing here
...
censoredString = r.Replace(InputString, "****");
...
//if they are the same, return true
return (input == censoredString);
}
}
and then use that class in your Button code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
string censored = null;
if( !CheckString(TextBox1.Text, censored) ){
TextBox1.Text = censored;
lblError.Text = "You cursing sombitch."
}
End Sub
Hope this helps.
Manuel
Sandy wrote: Hello -
This code was snagged by me from the Internet and altered. Its
purpose is to check for swear words. It works the way it currently is, but I
need it to be more generic -- i.e., I don't want it to refer to TextBox1 or
Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I
have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
You could achieve this by e.g. creating a new class with a static
method called
public static bool CheckString( string input, string censoredString )
that returns a bool indicating whether it had to censor the string.
The censored string is written into the second string reference you
pass.
Since I am not familiar with VB, here is the C# for that.
public class SwearWordChecker{
public static string CheckString( string input, string censoredString
){
censoredString = input;
// do your thing here
...
censoredString = r.Replace(InputString, "****");
...
//if they are the same, return true
return (input == censoredString);
}
}
and then use that class in your Button code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
string censored = null;
if( !CheckString(TextBox1.Text, censored) ){
TextBox1.Text = censored;
lblError.Text = "You cursing sombitch."
}
End Sub
Hope this helps.
Manuel
Sandy wrote: Hello -
This code was snagged by me from the Internet and altered. Its
purpose is to check for swear words. It works the way it currently is, but I
need it to be more generic -- i.e., I don't want it to refer to TextBox1 or
Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I
have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
Thanks so much, Elton. It works beautifully!
Sandy
"Elton W" wrote: Hi Sandy,
You can try
Public Sub CheckString(txtBox As TextBox, lbl As Label) Dim alWordList as New ArrayList Dim inputstring as string = txtBox.Text Dim origtext as String = inputstring
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) inputString = r.Replace(inputString, "****") Next
txtBox.Text = inputString If Not origtext.Equals(inputString) Then lbl.Text = "Funky words, please replace." Else lbl.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1, Label1) End Sub "Sandy" wrote:
Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
Thanks so much, Elton. It works beautifully!
Sandy
"Elton W" wrote: Hi Sandy,
You can try
Public Sub CheckString(txtBox As TextBox, lbl As Label) Dim alWordList as New ArrayList Dim inputstring as string = txtBox.Text Dim origtext as String = inputstring
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) inputString = r.Replace(inputString, "****") Next
txtBox.Text = inputString If Not origtext.Equals(inputString) Then lbl.Text = "Funky words, please replace." Else lbl.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1, Label1) End Sub "Sandy" wrote:
Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
Thanks for your response!
Sandy
"DoesDotNet" wrote: You could achieve this by e.g. creating a new class with a static method called
public static bool CheckString( string input, string censoredString )
that returns a bool indicating whether it had to censor the string. The censored string is written into the second string reference you pass. Since I am not familiar with VB, here is the C# for that.
public class SwearWordChecker{ public static string CheckString( string input, string censoredString ){ censoredString = input; // do your thing here ... censoredString = r.Replace(InputString, "****"); ... //if they are the same, return true return (input == censoredString); } }
and then use that class in your Button code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click string censored = null; if( !CheckString(TextBox1.Text, censored) ){ TextBox1.Text = censored; lblError.Text = "You cursing sombitch." } End Sub
Hope this helps. Manuel Sandy wrote: Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
Thanks for your response!
Sandy
"DoesDotNet" wrote: You could achieve this by e.g. creating a new class with a static method called
public static bool CheckString( string input, string censoredString )
that returns a bool indicating whether it had to censor the string. The censored string is written into the second string reference you pass. Since I am not familiar with VB, here is the C# for that.
public class SwearWordChecker{ public static string CheckString( string input, string censoredString ){ censoredString = input; // do your thing here ... censoredString = r.Replace(InputString, "****"); ... //if they are the same, return true return (input == censoredString); } }
and then use that class in your Button code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click string censored = null; if( !CheckString(TextBox1.Text, censored) ){ TextBox1.Text = censored; lblError.Text = "You cursing sombitch." } End Sub
Hope this helps. Manuel Sandy wrote: Hello -
This code was snagged by me from the Internet and altered. Its purpose is to check for swear words. It works the way it currently is, but I need it to be more generic -- i.e., I don't want it to refer to TextBox1 or Label1 directly; I want to be able to plug in the name of any textbox into CheckString(TextBox1.Text), instead of just a specific textbox. [I have many textboxes on one page that all need to be checked.]
Public Sub CheckString(inputstring as string) Dim alWordList as New ArrayList
Dim origtext as String origtext = TextBox1.Text
dim xmlDocPath as string = server.mappath("bad_words2.xml") dim xmlReader as XmlTextreader = New xmlTextReader(xmlDocPath) While (xmlReader.Read()) if xmlReader.Nodetype=xmlNodeType.Text then alWordList.Add(xmlReader.Value) End If End While xmlReader.Close()
Dim r as Regex dim element as string dim output as string For Each element in alWordList r = New Regex("\b" & element) InputString = r.Replace(InputString, "****") Next
TextBox1.Text = InputString If origtext <> TextBox1.Text Then Label1.Text = "Funky words, please replace." Else Label1.Text = "Okay." 'This is just included for testing End If End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click CheckString(TextBox1.Text) End Sub
Any suggestions will be greatly appreciated! -- Sandy
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robert |
last post by:
Where can i find a free web- based VC++ course? (also i've to dowanload it)
I'm interested also in VB and C++
thanks, Robert
|
by: Steph |
last post by:
Hi.
I'm very new to MS Access and have been presented with an Access database
of contacts by my employer.
I am trying to redesign the main form of the database so that a button
entitled...
|
by: gs |
last post by:
I have searched Google, MSDN,... for a week. I am still unable to make
available functions in my csharp dll as native windows functions for some
legacy non dotnet application
I just want to...
|
by: Sandy |
last post by:
Hello -
This code was snagged by me from the Internet and altered. Its purpose is
to check for swear words. It works the way it currently is, but I need it to
be more generic -- i.e., I don't...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: Tarun Mistry |
last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies
to both (apologies if it breaks some group rules).
I am making a web app in asp.net using c#. This is the first fully OO...
|
by: AdawayNoSpam |
last post by:
Said that I have the following class
Class MyRootClass(Of T)
End Class
Class MySubClass1(Of T)
Inherits MyRootClass(Of T)
End Class
|
by: |
last post by:
I'm looking for some design guidance on a collection of projects I'm working
on.
The project involves a bunch of websites constructed out of a collection of
user controls. Different user...
|
by: Bruce |
last post by:
I need to re-write an old .ASP application in a C# webservice. No problem,
right? Well, I also need to use a DCom object to connect to our SAP system.
Unfortunately, I'm unable to make that work....
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |