字符串存在判定,以后不用自己写了,直接copy

string[] strArray = {"ABCDEFG", "HIJKLMNOP"};
string findThisString = "JKL";
int strNumber;
int strIndex = 0;
for (strNumber = 0; strNumber < strArray.Length; strNumber++)
{
    strIndex = strArray[strNumber].IndexOf(findThisString);
    if (strIndex >= 0)
        break;
}
Console.WriteLine("String number: {0}\nString index: {1}",
    strNumber, strIndex);

你可能感兴趣的:(字符串存在判定,以后不用自己写了,直接copy)