我有以下字符串:
abc
def
abc
xyz
pop
mmm
091
abc
Run Code Online (Sandbox Code Playgroud)
我需要abc用数组中的那些替换所有出现的,["123", "456", "789"]所以最终的字符串将如下所示:
123
def
456
xyz
pop
mmm
091
789
Run Code Online (Sandbox Code Playgroud)
我想在没有迭代的情况下完成它,只需要单个表达式.我该怎么做?
这是一个"单表达式版本":
编辑:委托代替Lambda for 3.5
string[] replaces = {"123","456","789"};
Regex regEx = new Regex("abc");
int index = 0;
string result = regEx.Replace(input, delegate(Match match) { return replaces[index++];} );
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
939 次 |
| 最近记录: |