Solved

Replace

Posted on 2009-06-30
6
260 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
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…
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…

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now