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