

The example includes a call to the IndexOf(String) method if a substring is found in a string instance. String.indexOf(searchValueString, offsetInteger) returns an index integer or -1 if the string isnt found. If you are interested in the position of the substring value in the current instance, you can call the IndexOf method to get the starting position of its first occurrence, or you can call the LastIndexOf method to get the starting position of its last occurrence. ' Does 'This is a string.' contain 'this'? ' The example displays the following output: String^ s1 = "The quick brown fox jumps over the lazy dog" Ĭonsole::WriteLine( "Is the string, s2, in the string, s1?: ", comp, s.Contains(sub1, comp))


If "fox" is found in the string, it also displays its starting position. The following example determines whether the string "fox" is a substring of a familiar quotation.
