Blog Details

String Function


* String Function :-

1) String Length

  • The length of a string (a string object) is found in the built in property length:

Example :

<html> <body> <script> var txt = "Hello World!"; document.write("<p>" + txt.length + "</p>"); var txt="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; document.write("<p>" + txt.length + "</p>"); </script> </body> </html>

Output :

12 26  

2) Matching Content

  • The match() method can be used to search for a matching content in a string:

Example :

<html> <body> <script> var str="Hello world!"; document.write(str.match("world") + "<br>"); document.write(str.match("World") + "<br>"); document.write(str.match("world!")); </script> </body> </html>

Output :

world null world!  

3) Replacing Content

  • The replace() method replaces a specified value with another value in a string.

Example :

str="Please visit Microsoft!" var n=str.replace("Microsoft","W3Schools");  

4) Upper Case and Lower Case

  • A string is converted to upper/lower case with the methods toUpperCase() / toLowerCase():

Example :

var txt="Hello World!";       // String var txt1=txt.toUpperCase();   // txt1 is txt converted to upper var txt2=txt.toLowerCase();   // txt2 is txt converted to lower  

5) Convert a String to an Array

  • A string is converted to an array with the built in method string.split():

Example :

txt="a,b,c,d,e"   // String txt.split(",");   // Split on commas txt.split(" ");   // Split on spaces txt.split("|");   // Split on pipe



Latest posts

Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t


<ol> <li><a href="

Creating Model

<ol> <li><a href="

Get Free Quote