Solved

Replace

Posted on 2009-06-30
6
263 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
  • 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
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!

 
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

Suggested Solutions

Title # Comments Views Activity
regex to extract ip:john 17 77
Regex code,how to do this? 3 47
Extract a value from a variable using regular expression 4 45
Regex - Capture everything between two strings. 8 28
I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
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…

749 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