0

我需要使用正则表达式替换源代码文档中的所有字符串,如下
strcpy(x,"string is string")所示_tcscpy(x,_T("string is string"));
实际上,我需要用 T_marco 包围函数中的所有字符串
如何在 c# 中定义正则表达式模式来做到这一点?
谢谢

4

2 回答 2

1

如果您需要这样做,您可以简单地从编辑菜单运行替换,使用strcpy(x,"string is string")被替换并_tcscpy(x,_T("string is string"));作为替换,设置“整个项目”。

于 2012-05-24T08:46:43.983 回答
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/

于 2012-05-24T09:19:13.067 回答