String position: Difference between revisions
From Coderwiki
More actions
new: info, example, specific programming language |
(No difference)
|
Latest revision as of 12:25, 15 August 2025
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.
Example
edit edit source
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