How to find a substring in a String array? I need to find a substring in an array of strings. The string can be located in any part of the array (element) or inside the element. (middle of line) I tried: Array.IndexOf(arrayStrings,searchItem)but searchItem should be an EXACT match that can be found in arrayStrings. In my case, searchItem is part of the complete element in arrayStrings.
string [] arrayStrings = {
"Welcome to SanJose",
"Welcome to San Fancisco","Welcome to New York",
"Welcome to Orlando", "Welcome to San Martin",
"This string has Welcome to San in the middle of it"
};
lineVar = "Welcome to San"
int index1 =
Array.IndexOf(arrayStrings, lineVar, 0, arrayStrings.Length);
I need to check if the lineVar variable is present in arrayStrings. lineVar can have different lengths and meanings.
What would be the best way to find this substring in an array string?
source
share