This is a naive implementation - I know that there are algorithms like KMP
However I was trying to implement it as best as I can.
string test = "giladdarmonwhatareyoudoing";
int index = StrStr(test, "are");
//Returns an index to the first occurrence of str2 in str1,
//or a -1 pointer if str2 is not part of str1.
public int StrStr(string test, string strToFind)
{
for (int i = 0; i < test.Length; i++)
{
if (test[i] == strToFind[0])
{
int j;
for (j = 0; j < strToFind.Length; j++)
{
if (test[i + j] != strToFind[j])
{
break;
}
}
if (j == strToFind.Length)
{
return i;
}
}
}
return -1;
}