By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,686 Members | 2,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,686 IT Pros & Developers. It's quick & easy.

regex replace question

P: n/a
I am trying to replace any occurance of minus-point "-." with
minus-zero-point "-0."

My regex: Regex repoint_num = new Regex(@"\-\.");

My data: string xyz = "-.9";

My command: repoint_num.Replace(expr, "0.");

The match is detected but the replace does not occur.

I'm stupid I know, but how do I correct this?


Sep 5 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
We have these moments here at Golden Acres:
My (new) command: expr = repoint_num.Replace(expr, "0.");

"Mark_B" wrote:
I am trying to replace any occurance of minus-point "-." with
minus-zero-point "-0."

My regex: Regex repoint_num = new Regex(@"\-\.");

My data: string xyz = "-.9";

My command: repoint_num.Replace(expr, "0.");

The match is detected but the replace does not occur.

I'm stupid I know, but how do I correct this?

Sep 5 '08 #2

P: n/a
On Fri, 05 Sep 2008 12:16:11 -0700, Mark_B
<Ma***@discussions.microsoft.comwrote:
I am trying to replace any occurance of minus-point "-." with
minus-zero-point "-0."

My regex: Regex repoint_num = new Regex(@"\-\.");

My data: string xyz = "-.9";

My command: repoint_num.Replace(expr, "0.");

The match is detected but the replace does not occur.

I'm stupid I know, but how do I correct this?
Impossible to say if you don't post the code you're using, and you
obviously haven't done that.

But, based on the narrative, I'd say there's a possibility you're
expecting the string referenced by "xyz" to change, which won't work.
Strings are immutable. The Replace() method returns a new string, and
that's the one you should use if you want the altered value.

Alternatively, the code you posted is closer to your actual code that one
might hope, in which case at least part of the problem is that you're
passing "expr" to the Replace() method when you really want to search the
string referenced by "xyz".

By the way, if you want "-." to be replaced by "-0.", why isn't your
replacement string "-0."?

If the above doesn't clear things up, you really should post the actual
code. Psychic debugging can take us only so far.

Pete
Sep 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.