HTML

String Methods:
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
1. String length():

  • 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");
3. Search():
  • 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.


EX:
Code:






















OUTPUT: