Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.
Revision as of 12:25, 15 August 2025 by Dylan (talk | contribs) (new: info, example, specific programming language)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Most programming languages implement a position or indexOf method on strings.

This method will return the index of the first character of the substring in the main string.

The following Java code shows the indexOf method:

String haystack = "Hello world, Java is a programming language";
String needle = "Java";
int position = haystack.indexOf(needle);
System.out.println(position); // 13

Specific programming languages

edit edit source