在 C# 中枚举正则表达式替换的最佳方法是什么。
例如,如果我希望将每个 "
最佳答案
您可以在指定为 MatchEvaluator
的匿名方法中使用递增计数器打回来。 (?<=…)
是正向后看;它由正则表达式求值器匹配,但未删除。
string input = "a <intent-filter data=a /> <intent-filter data=b />";
int count = 0;
string result = Regex.Replace(input, @"(?<=\<intent-filter)",
_ => " android:label=label" + count++);
关于C# 枚举正则表达式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22068816/