replacement regular expression
-
hi, I need a regular expression to replace / with // in a richTextBox1. how is this done? I have this:
string replace_1 = Regex.Replace(richTextBox1.Text, @"/", @"//");
but it doesn't replace the string with the replacement string in the richTextBox1. can you show me something that would work? thanks in advance, Stephen -
hi, I need a regular expression to replace / with // in a richTextBox1. how is this done? I have this:
string replace_1 = Regex.Replace(richTextBox1.Text, @"/", @"//");
but it doesn't replace the string with the replacement string in the richTextBox1. can you show me something that would work? thanks in advance, StephenWhy do you need a regex here ? The string class is well able to do this for you. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
Why do you need a regex here ? The string class is well able to do this for you. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
can you show me what the code would look like. I tried this:
string replace_1 = richTextBox1.Text; replace_1.Replace("/", "//"); richTextBox1.Text = ""; richTextBox1.Text = replace_1;
but no luck.Have you looked in the debugger ? I think the rich text box is your problem. Christian I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
-
can you show me what the code would look like. I tried this:
string replace_1 = richTextBox1.Text; replace_1.Replace("/", "//"); richTextBox1.Text = ""; richTextBox1.Text = replace_1;
but no luck.RichTextBox1.Text.Replace(@"/", @"//");
You're going to run into a problem each time you run this though. Every time you run this, or any other similar function, you'll end up doubling the number of slash marks EVERY time it's run. So...
/ This is a test...
will become
// This is a test...
will become
//// This is a test...
will become
//////// This is a test...
Unless you put in some code that checks for this condition... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
RichTextBox1.Text.Replace(@"/", @"//");
You're going to run into a problem each time you run this though. Every time you run this, or any other similar function, you'll end up doubling the number of slash marks EVERY time it's run. So...
/ This is a test...
will become
// This is a test...
will become
//// This is a test...
will become
//////// This is a test...
Unless you put in some code that checks for this condition... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
I'm having horrible luck with this. i made a simple simple app with one regular textBox1, and a button. on the button's click I have this code: textBox1.Text.Replace(@"/", @"//"); just like you showed me. it still won't work (I also tried it with the richTextBox, and still no luck. I'm so annoyed at this. It's plagueing me. any ideas? thanks
-
I'm having horrible luck with this. i made a simple simple app with one regular textBox1, and a button. on the button's click I have this code: textBox1.Text.Replace(@"/", @"//"); just like you showed me. it still won't work (I also tried it with the richTextBox, and still no luck. I'm so annoyed at this. It's plagueing me. any ideas? thanks
-
I'm having horrible luck with this. i made a simple simple app with one regular textBox1, and a button. on the button's click I have this code: textBox1.Text.Replace(@"/", @"//"); just like you showed me. it still won't work (I also tried it with the richTextBox, and still no luck. I'm so annoyed at this. It's plagueing me. any ideas? thanks
Hi! It's quite simple, strange that no-one noticed so far.
string.Replace(a,b)
returns a new string holding the text after the replacement. So if you simply write:richTextBox1.Text = richTextBox1.Text.Replace("/","//");
you should be fine. Regards, mav
-
Hi! It's quite simple, strange that no-one noticed so far.
string.Replace(a,b)
returns a new string holding the text after the replacement. So if you simply write:richTextBox1.Text = richTextBox1.Text.Replace("/","//");
you should be fine. Regards, mav
:doh: Smack! What a bad day yesterday... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
:doh: Smack! What a bad day yesterday... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome