2012-03-19 16 views
0

文字列のコレクションからその文字列を使用して文字列を見つける必要があります。このサブストリング が開始されている必要があります。LINQを使用して文字列のリスト内の部分文字列を見つける方法

+0

してみてください。このhttp://stackoverflow.com/questions/2402529/substring-with-linqと、このhttp://stackoverflow.com/questions/418187/how-to-use-linq-return-substring-of-fileinfo-name – PresleyDias

答えて

9
collection.FirstOrDefault(s => s.StartsWith(whatever)) 
+0

ありがとう、働いてくれてありがとう – YogeshWaran

+2

もし複数のファイルが存在する場合は、 'collection.Where(s => s。 StartsWith(何でも)) ' – joshuahealy

+0

@appclay:ありがとう – YogeshWaran

2

あなたはこのような何かを行うことができ、

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) 
     { 
     } 
関連する問題