【发布时间】:2012-03-19 05:01:50
【问题描述】:
我需要使用它的子字符串从字符串集合中找出一个字符串。这个子字符串 必须在开始。
【问题讨论】:
我需要使用它的子字符串从字符串集合中找出一个字符串。这个子字符串 必须在开始。
【问题讨论】:
collection.FirstOrDefault(s => s.StartsWith(whatever))
【讨论】:
collection.Where(s => s.StartsWith(whatever))
你可以这样做,
List<string> collection = new List<string>();
collection.Add("example sample");
collection.Add("sample");
collection.Add("example");
var varSubstring = collection.Where(x => x.IndexOf("sample")==0).ToList();
foreach (var vartemp in varSubstring)
{
}
【讨论】: