473,806 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regex.Replace issue

Hi All,

I am having problem using Regex.Replace.I am trying to search all the
strings present in a .cs file and replace it with a different string .I am
doing this by searching all the code which comes under ""(double quotes).

Code for Replacement:
System.Text.Reg ularExpressions .Regex.Replace( str, "\"" + fstring + "\"",
resxName + "." + ResxItemName);

The string under double in 'fstring'
' "\"" ' is used since I am reading the file using TextWriter.

Issue is I get parsing error for the following:
1.When ftsring="****** Hello*****"
2.When fstring="{1,673 0(100329.oti(*. 8))}"

Also fstring="\\Test \\\TestSource" doesnot give an error but the 'ftsring'
is not replaced either.

Please let me know where am I going wrong.

Thanx in advance!
Regards,
Neeta

Dec 5 '06 #1
2 1221
I could answer this question, if I could understand it!

--
HTH,

Kevin Spencer
Microsoft MVP
Logostician
http://unclechutney.blogspot.com

There is a madness to my method.

"Neeta" <Ne***@discussi ons.microsoft.c omwrote in message
news:EF******** *************** ***********@mic rosoft.com...
Hi All,

I am having problem using Regex.Replace.I am trying to search all the
strings present in a .cs file and replace it with a different string .I am
doing this by searching all the code which comes under ""(double quotes).

Code for Replacement:
System.Text.Reg ularExpressions .Regex.Replace( str, "\"" + fstring + "\"",
resxName + "." + ResxItemName);

The string under double in 'fstring'
' "\"" ' is used since I am reading the file using TextWriter.

Issue is I get parsing error for the following:
1.When ftsring="****** Hello*****"
2.When fstring="{1,673 0(100329.oti(*. 8))}"

Also fstring="\\Test \\\TestSource" doesnot give an error but the 'ftsring'
is not replaced either.

Please let me know where am I going wrong.

Thanx in advance!
Regards,
Neeta

Dec 5 '06 #2
Neeta <Ne***@discussi ons.microsoft.c omwrote:
I am having problem using Regex.Replace.I am trying to search all the
strings present in a .cs file and replace it with a different string .I am
doing this by searching all the code which comes under ""(double quotes).

Code for Replacement:
System.Text.Reg ularExpressions .Regex.Replace( str, "\"" + fstring + "\"",
resxName + "." + ResxItemName);

The string under double in 'fstring'
' "\"" ' is used since I am reading the file using TextWriter.

Issue is I get parsing error for the following:
1.When ftsring="****** Hello*****"
2.When fstring="{1,673 0(100329.oti(*. 8))}"

Also fstring="\\Test \\\TestSource" doesnot give an error but the 'ftsring'
is not replaced either.

Please let me know where am I going wrong.
Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2088
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 http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800 function fxnParseIt() { var sInputString = 'asp and database';
3
1177
by: Richard | last post by:
Trying to wrap my brain around Regex for the first time... I need to be able to replace Sql @NamedParameters with "?" for compliance with an extremely lame 3rd party Odbc driver. I know that this should be fairly straighforward in Regex but I'm not a Regex guru. Does anybody know how to turn this {not real Sql but demonstrates my issue}: SELECT * FROM Customers WHERE State=@State AND LastName LIKE @LastName into this
7
2755
by: Rocky Moore | last post by:
I have a web site called HintsAndTips.com. On this site people post tips using a very simply webform with a multi line TextBox for inputing the tip text. This text is encode to HTML so that no tags will remain making the page safe (I have to convert the linefeeds to <BR>s because the Server.EncodeHTML does not do that it seems). The problem is that users can use a special tag when editing the top to specify an area of the tip that will...
6
1776
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") %>',"(\d{3})(\d{3})(\d{4})","($1) $2-$3") runat="server"/> I have this inside my Repeater and want it to filter the field during bind. I can do it afterwards by just looping through the repeater items, but that is extra work and time.
6
8890
by: Chris Anderson | last post by:
Anyone know of a fix (ideally) or an easy workaround to the problem of escape characters not working in regex replacement text? They just come out as literal text For example, you'd think that thi Regex.Replace("<stuff>text</stuff>", "<stuff>", "<stuff>\n" would give yo <stuff text</stuff
1
2012
by: rh | last post by:
hi all, take the following 2 c# lines: 1) str = Regex.Replace(str, ".*AAA", ""); 2) str = Regex.Replace(str, "^.*AAA", ""); notice that the only difference is that the pattern in line 2 has a starter marker (^). if str is large and does not contain the pattern, line 1 takes much much longer to complete than line 2 and cpu goes nearly full throttle.
3
4646
by: Deanna | last post by:
I'm trying to use Regex.Replace to replace a single word in a string, but I have to pass in the string. It won't ever match, but if I hard- code the word it works fine. Please help!! string stringToAlter = "ab cd ef gh"; // --- Pattern entered as string works fine string pat1 = @"\bcd\b"; string newStg1 = Regex.Replace(stringToAlter, @pat1, "xxx"); WriteLine("first try = " + newStg1);
15
50273
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
3
1939
by: Curious | last post by:
I have another question about Regular Expression. If I use: if (temp.Contains("Ending") == true) { temp = System.Text.RegularExpressions.Regex.Replace(temp, "Ending", "Beginning"); } It seems that while "Ending" is replaced with "Beginning", it also
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10371
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10110
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.