Strings | Sololearn: Learn to code for FREE!



How can I use IndexOf to search in a string?

12/21/2019 12:27:10 AM

Tamim Jabr

1 Answer

New Answer


String s = "SoloLearn earns good vibes"; int pos = s.IndexOf("ear"); Console.WriteLine(pos); // IndexOf method returns the offset of the given // argument within a String object // Offset is a zero based positive value Console.WriteLine(s.IndexOf("ear", pos + 1)); // A second optional argument may be passed // as a starting offset where the search shall begin