Firstly, sorry if the title sounds confusing.
How do I find the index of an item in a list string when only a substring of that item is known?
Like, I have a list called directories. It has C:\test, C:\new and C:\files (3 items).
Using the word "new" only, how can I find the ind开发者_JAVA百科ex number of C:\new (that is 1) in directories?
I am using .NET Framework 4.0, if that matters.
Thanks in advance.
try this
List<string> tst = new List<string>() { @"C:\test", @"C:\new", @"C:\files" };
var idx = tst.FindIndex(x => x.Contains("new"));
You can try something like
int i = new List<string>
{
@"C:\test",
@"C:\new",
@"C:\files"
}.FindIndex(0, x => x.Contains("new"));
精彩评论