473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

regex replace question

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
2 1355
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jon Maz | last post by:
Hi All, Am getting frustrated trying to port the following (pretty simple) function to CSharp. The problem is that I'm lousy at Regular Expressions.... //from...
16
by: Stephane | last post by:
Hi, I'm trying to replace parenthesis using Regex.replace but I'm always having this error: System.ArgumentException: parsing ":-)" - Too many )'s. Parameter name: :-) Here's my code: ...
1
by: Theo Chakkapark | last post by:
I'm having issues trying to replace text with PHP. For example, if I have a string of text that reads: {tag} And want to replace that with: $_POST
6
by: tshad | last post by:
Is there a way to use Regex inside of a tag, such as asp:label? I tried something like this but can't make it work: <asp:label id="Phone" text=Regex.Replace('<%# Container.DataItem("Phone")...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
4
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said,...
9
by: Whitless | last post by:
Okay I am ready to pull what little hair I have left out. I pass the function below my String to search, my find string (a regular expression) and my replace string (another regular expression)....
6
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
0
by: Karch | last post by:
I have these two methods that are chewing up a ton of CPU time in my application. Does anyone have any suggestions on how to optimize them or rewrite them without Regex? The most time-consuming...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.