how to return startindex of basestring as soon as it contains the substring value
Code:
public static int StringMatch(string baseStr, string compStr) {
int count = 0;
int index = 0;
for (int i = 0; i < baseStr.Length; i++)
{
for (int j = 0; j < compStr.Length; j++)
{
if (baseStr[i]==compStr[j])
{
index = i; // i need to return indexof the first character of basestring
count++;
}
if(count==compStr.Length)
{
Console.WriteLine("string match");
}
}
}
return index;
}
static void Main(string[] args)
{
string txt = "fftf kargi kargi";
string phrase = "kargi";
int res = StringMatch(txt, phrase);
Console.WriteLine(res);
}
}
}