Solved

Replace

Posted on 2009-06-30
6
264 Views
Last Modified: 2012-05-07
I have the below expression
string str1="<overmight express="\23\" optin="\test\">;

I want to replace optin value from test to advance.

I am unable to do this replace in c#. Could someone let me know.

Thanks

0
Comment
Question by:smiller473
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24748910
someVar = RegEx.Replace(text_to_search, @"optin=""\\test\\""","optin=""\advance\""")
0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 24748934
Stupid phone ;)

use instead:

    someVar = RegEx.Replace(text_to_search, @"optin=""\\test\\""", @"optin=""\advance\""")
0
 

Author Comment

by:smiller473
ID: 24749163
It's not working
string OptInFlag = "<OverLimitIntercept ExpirationDate=\"20090831\" OptIn=\"NotSeen\" NumberOfInterceptsDisplayed=\"0\" DateLastModified=\"20090719 09:32:23.938\" />";

                    
                  string someVar = System.Text.RegularExpressions.Regex.Replace(OptInFlag, @"OptIn=""\\NotSeen\\""", @"OptIn=""\Seen\""");
                  

Its not replacing the text to seen.

Do let me know
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Accepted Solution

by:
ddrudik earned 50 total points
ID: 24749995
Here's my modified suggestion.  Note the extra \ chars in the match pattern was the issue.
using System;
namespace myapp
{
    class Class1
    {
        static void Main(string[] args)
        {
            string OptInFlag = "<OverLimitIntercept ExpirationDate=\"20090831\" OptIn=\"NotSeen\" NumberOfInterceptsDisplayed=\"0\" DateLastModified=\"20090719 09:32:23.938\" />";
            string someVar = System.Text.RegularExpressions.Regex.Replace(OptInFlag, @"(?<=<OverLimitIntercept[^>]*\sOptIn="")NotSeen(?="")", @"Seen");
            Console.WriteLine(someVar);
        }
    }
}

Open in new window

0
 

Author Closing Comment

by:smiller473
ID: 31598504
Thanks, it helped.
0
 
LVL 27

Expert Comment

by:ddrudik
ID: 24798303
Thanks for the question and the points.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
As most anyone who uses or has come across them can attest to, regular expressions (regex) are a complicated bit of magic. Packed so succinctly within their cryptic syntax lies a great deal of power. It's not the "take over the world" kind of power,…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question