Find the first occurrence of “planet” within a string.
String |
The indexOf() method retrieves the position of the first occurrence of specified character(s) within a string.
Tip: Utilize the lastIndexOf method to obtain the position of the last occurrence of specified character(s) within a string.
“Choose one from the following options:”
public |
public |
public |
public |
Description |
Parameters |
str |
“A String value representing the string to be searched for.” |
fromIndex |
“An integer value representing the starting index position for the search.” |
char |
“An integer value representing a single character, such as ‘A’, or a Unicode value.” |
Returns |
Return an integer value indicating the index of the first occurrence of the character in the string, or -1 if it is not found. |
Locate the first instance of the letter “e” in a string, commencing the search from position 5.
public |