【发布时间】:2015-04-01 08:44:04
【问题描述】:
我有一个字符串,像这样:
string str = "id=1,id=2,id=5,id=22";
然后,我在这个字符串上应用一些正则表达式,以获取标识符:
var idMatchCollection = regex.Matches(str);
foreach(Match match in idMatchCollection)
{
var newValue = SomeFunction(match.toString());
// i want to replace newValue for Match which we have in foreach with newValue. That reflect in sting str.
}
所以,最终的输出应该是这样的:
str = "id=234,id=576,id=5767,id=756765"
(234,567,5767,756765)是我在foreach循环for(1,2,5,22)中通过函数得到的值
【问题讨论】:
-
您是否有一个
Dictionary<string, string>,其键与ids 匹配,可用于执行替换? -
我不明白......输入看起来如何,输出应该看起来如何?
-
我不想使用字典。我想要一些不同的方法来替换每场比赛。
标签: c# asp.net regex asp.net-mvc c#-4.0