Solved

Replace

Posted on 2009-06-30
6
258 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 74

Expert Comment

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

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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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

706 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

14 Experts available now in Live!

Get 1:1 Help Now