find()
Table of Contents
Overview
The find() function takes string and searchString as arguments. It returns the first occurrence index of searchString's first character in the string.
If the searchString is not found in the string, it returns -1.
Note:
- Index starts from 0.
- This function performs a case-sensitive search.
Return Type
- Number
Syntax
<variable> = <string>.find( );
(OR)
<variable> = find( <string>, <searchString>);
(OR)
<variable> = <string>.indexOf(<searchString>);
(OR)
<variable> = indexOf(<string>,<searchString>);
Parameter | Description | Data type |
---|---|---|
<variable> | Variable which will contain the returned index number. | NUMBER |
<string> | The string from which the index number will be returned. | TEXT |
<searchString> | This string's first character's first occurrence will be checked in the string. | TEXT |
Examples
text="Hello world, welcome to the universe";
firstIndex = text.find("e"); //returns 1
firstIndex = text.find("e"); //returns 1