0

I have a string as

"AND A.BrandId IN (0,1,3,5,9,10) AND AgeGroup IN (0-24,24-36) AND Gender IN (0,1,2)"

and I want to replace the "AgeGroup IN (0-24,24-36)" with other text, keeping the remaining part of the string as it as. How to do that?

4

2 回答 2

1

使用该String.Replace("Old String", "New String")方法会更容易,而不是使用正则表达式

例子:

string oldFoo = "AND A.BrandId IN (0,1,3,5,9,10) AND AgeGroup IN (0-24,24-36) AND Gender IN (0,1,2)";
string newFoo;
newFoo = oldFoo.Replace("AgeGroup IN (0-24,24-36)", "newFooText");


有关 String.Replace() 方法的更多信息:MSDN

于 2012-05-03T03:40:08.063 回答
0

如果您认为您的字符串可能会更改为 AgeGroup IN (0-2, 0-4, 24-56,24-36, 4-12) 之类的东西,您可以使用正则表达式将该字符串替换为其他字符串。

                string newString = Regex.Replace(str, @"AgeGroup\sIN\s\((\s*\d*[-]\d*,*)*\)", "Other_Text");

你可以看看这里

于 2012-05-03T05:42:30.707 回答