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 1380
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: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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: 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: 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,...
| |