0

I need to replace a all string in source code document using regex like this:
strcpy(x,"string is string") become _tcscpy(x,_T("string is string"));.
actually , i need surround all string in function with T_ marco
How to define a regular expression pattern in c# to do this?
thanks

nguyen
  • 171
  • 6
  • 13

2 Answers2

1

If you need to do that, you could simply run a Replace from Edit menu using strcpy(x,"string is string") to be replaced and _tcscpy(x,_T("string is string")); as substitution, setting "Whole project".

Marco
  • 56,740
  • 14
  • 129
  • 152
1

First, you import API of regular expression in your class for use it:

using System.Text.RegularExpressions;

Second in your method, instantiate new Regex:

Regex regexName = new Regex(@"string of regexExpression", RegexOptions.IgnoreCase);

Third, you analize your string or for extract your prefered part of string:

MatchCollection nameOfResult = regexName.Matches(this.yourString);
foreach (Match result in nomeOfResult)
        {
            System.out.println(result.ToString());
        }

Third-one, if you replace part of string corresponding your regex:

Regex.Replace(yourString, regexName);

Try by this pattern : strcpy.*x,.*string.*is.string. For pattern or for test pattern use this: http://rubular.com/ or this: http://myregexp.com/

carminePat
  • 159
  • 2
  • 5
  • 13