|
-
Jul 3rd, 2012, 12:31 AM
#1
Thread Starter
Junior Member
[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, #-#-# , " ")
-
Jul 3rd, 2012, 12:56 AM
#2
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.
-
Jul 3rd, 2012, 12:59 AM
#3
Thread Starter
Junior Member
Re: Variable That Equals Anything
 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.
Last edited by ImSimplyLegit; Jul 3rd, 2012 at 01:07 AM.
-
Jul 3rd, 2012, 01:24 AM
#4
Hyperactive Member
Re: Variable That Equals Anything
 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.
-
Jul 3rd, 2012, 01:28 AM
#5
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:
-
Jul 3rd, 2012, 11:54 AM
#6
Thread Starter
Junior Member
Re: Variable That Equals Anything
 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
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|