1

如何使用正则表达式 ( ) 替换这些尾随"N megapixels"字符串?""RegEx.Replace

例子:

如果我们输入:“Powershot Yellow 12.1 Megapixels”,结果将是:“Powershot Yellow”

如果我们输入:“Powershot Black II 10 Megapixels”,结果将是:“Powershot Black II”

4

3 回答 3

3

像这样简单的东西怎么样...

var newStr = Regex.Replace(input, @"\s+[\d\.]+\s*Megapixels", "", RegexOptions.IgnoreCase);
于 2011-07-05T18:01:08.020 回答
0

试试这个:

var newString = Regex.Replace(candidate, @"\d+\.?\d+ Megapixels", "");
于 2011-07-05T18:01:10.747 回答
0
var camera = Regex.Replace(input, @"\s+[.\d]+\s+Megapixels", "", RegexOptions.IgnoreCase);
于 2011-07-05T18:20:35.160 回答