How to search for a Substring in String array? I need to search for a Substring in the string array. The string can be located in any part of the array (element) or within
Old school:
int index = -1;
for(int i = 0; i < arrayStrings.Length; i++){
if(arrayStrings[i].Contains(lineVar)){
index = i;
break;
}
}
If you need all the indexes:
List> indexes = new List>();
for(int i = 0; i < arrayStrings.Length; i++){
int index = arrayStrings[i].IndexOf(lineVar);
if(index != -1)
indexes.Add(new Tuple(i, index)); //where "i" is the index of the string, while "index" is the index of the substring
}