strstr
?strstr(p, 'Hello');
strstr('With my dog', p);
strstr(p, s);
strstr
in 7.24.5.7 says:strstr
optimizes the case of an empty string for the second argument. Undefined behavior is an error that need not be detected or diagnosed; it's entirely your responsibility as a programmer to avoid undefined behavior in the first place.strstr
parameters: 'If str or strSearch is NULL, the invalid parameter handler is invoked' and, 'The default invalid parameter invokes Watson crash reporting, which causes the application to crash' (http://msdn.microsoft.com/en-us/library/vstudio/ksazx244.aspx). String.Empty
as second parameter, it throws an IndexOutOfRangeException
IndexOutOfRangeException
null
as either first or second parameter a NullReferenceException
is thrown. Here it would be better to throw an ArgumentNullException
by using a guard clause. strToFind.Length > test.Length
test.Length - i > strToFind.Length
strToFind
to searchForm
or searchArgument
. if (test[i] strToFind[0])
and implementing the above we will get for
loop like str1
and str2
parameters mentioned in the comment, aren't the actual parameter names you're using. You can use paramref
for that:<paramref>
tag gives you a way to indicate that a word in the code comments, for example in a <summary>
or <remarks>
block refers to a parameter. The XML file can be processed to format this word in some distinct way, such as with a bold or italic font.<returns>
XML tag to specify a function's return value - the <summary>
tag should simply state what the function does, not cover all possible outcomes.StrStr
is actually not really a good name. StartIndexOf
or similar might be better.string
which would result in a nicer calling syntax. It would look like this then: