Solved

Replace

Posted on 2009-06-30
6
262 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Suggested Solutions

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…

825 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