我正在寻找一种聪明的方法来在字符串列表中查找带有特定字符的列表元素。查找字符串列表中的字符
我想找到的所有字符串,至极包含像字符串列表 - 符号: “?一个11”, “AB12”, “BB12”, “2 B 13”
我现在解决方案是这样的:
// Interates through all strings.
foreach (string currentString in listOfStrings)
{
if (currentString.Contains('?'))
{
// Found!
myStrings.Add(currentString);
}
}
是否有更好的方法来完成这项工作,也许像:
List<string> myStrings = listOfStrings.Select(z => z.Contains('?')).ToList();
任何想法?
更好是非常相对的。我会尝试codereview.SE。 – 2013-03-20 22:13:04