[RESOLVED] Variable That Equals Anything
I need to find and replace #-#-# with nothing in a richtextbox.
How would I tell it that if there is any number then a - then any number then - then any number. To replace #-#-# with a space. My attempted code is below.
Code:
RichTextBox1.Text = Replace(RichTextBox1.Text, #-#-# , " ")
Re: Variable That Equals Anything
You would use a regular expression for this. I'm far from an expert with regular expressions so I usually give them a miss but this seemed like a rather easy one so I figured I'd give it a go. This worked for me in my one simple test:
vb.net Code:
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text,
"\d-\d-\d",
String.Empty)
The "\d" in the pattern stands for any numeric digit.
Re: Variable That Equals Anything
Quote:
Originally Posted by
jmcilhinney
You would use a regular expression for this. I'm far from an expert with regular expressions so I usually give them a miss but this seemed like a rather easy one so I figured I'd give it a go. This worked for me in my one simple test:
vb.net Code:
RichTextBox1.Text = Regex.Replace(RichTextBox1.Text,
"\d-\d-\d",
String.Empty)
The "\d" in the pattern stands for any numeric digit.
Only thing is the Regex? It says it's not declared. What is it?
Edit: It also doesn't work because it takes your
Code:
Replace(RichTextBox1.Text, "\d-\d-\d",
Literaly and if you type \d-\d-\d then it will empty the string, but numbers will not work.
Re: Variable That Equals Anything
Quote:
Originally Posted by
ImSimplyLegit
Only thing is the Regex? It says it's not declared. What is it?
Edit: It also doesn't work because it takes your
Code:
Replace(RichTextBox1.Text, "\d-\d-\d",
Literaly and if you type \d-\d-\d then it will empty the string, but numbers will not work.
try to imports system.text.regularexpressions
then you can now declare the regex.
Re: Variable That Equals Anything
Regex is a class and, just like any other class or type at all for that matter, you have to either qualify it with its namespace or else import that namespace. The MSDN Library has a topic for every type it contains and each topic tells you what assembly (DLL) that type is defined in and what namespace it's a member of.
@marniel647, just to be precise, there is no declaration in that code. It's making use of the Regex class but not declaring the Regex class or a variable of the Regex type. This would be a declaration:
Re: Variable That Equals Anything
Quote:
Originally Posted by
marniel647
try to imports system.text.regularexpressions
then you can now declare the regex.
It Works! Thank you soooo so much. This code was needed to help organize a big list of classes for a college. ty:eek2: