String Methods:
we have 8 types of string methods.
2. String Indexof():
second method:
4. Substring:
5. Replace():
6.String.trim():
7. String case lowercase and uppercase:
EX:
OUTPUT:
we have 8 types of string methods.
- String length
- String Index
- Search for a string in a word
- Substring
- String replace
- String case lowercase and uppercase
- String trim
- String cut
- The Length property returns the length of a string.
- Syntax: var name="string";
- var name2=name.length;
2. String Indexof():
- It will return the index of the first occurrence of a specified text in a string.
- Syntax: var str="string";
- var pos=str.indexof("string part");
second method:
- Last IndexOf():It will return the index of the last occurrence of a specified text in a string.
- Syntax:var str="string";
- var pos=str.lastIndexOf("string part");
- It will search a sting a string for a specified value and returns the position of the match.
- Syntax: var str="string";
- var pos=str.search("string part");
4. Substring:
- It will extract a string and returns the extracted part in a new string.
- It will not accept negative vakues.
5. Replace():
- It will replace a specified value with another value.
- Syntax: var str="string";
- var pos=str.replace("string part");
6.String.trim():
- It wil removes the whitespace from both sides of a string.
7. String case lowercase and uppercase:
- It will convert from lower case to upper case and from upper case to lower case.
- to.LopwerCase:It will convertg into lower case.
- to.Upper:It will convert into uppercase.
Code:
OUTPUT: