如何在字符串数组中搜索子字符串?我需要在字符串数组中搜索子字符串。该字符串可以位于数组的任何部分(元素)或元素内部(字符串中间)。我已经尝试过:Array.IndexOf(arrayStrings,searchItem)
,但是searchItem必须与arrayStrings中的精确匹配才能被找到。在我的情况下,searchItem是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);
// index1 mostly has a value of -1; string not found
我需要检查arrayStrings数组中是否存在lineVar变量。lineVar的长度和值可能会不同。
什么是在数组字符串中查找这个子字符串的最佳方法?