Strings in javascript part 2

Operations and implementations on strings in javascript(split, replace and search)

Category: Java Script Tags: HTML, Java Script

Java Script tutorial 13

        Today I am going to show you some more important operations on string using javascript like
split, replace, search.

<script type="text/javascript">
var string1 = new String("Hello");
var string2 = "hi you are visiting dotnetlovers";

document.write("Split the string2 from 'are' so first part is : <b>" + string2.split('are')[0] + "
</b>and second is : <b>" + string2.split('are')[1] + "</b>.");

document.write("<br /><br />Replace 'H' to 'F' from string1: <b>" + string1.replace('H', 'F') + "</b>.");

document.write("<br /><br />Search position of 'are' from string2 <b>: " +'are') + "</b>.");


        In above code we split the string2 by are using split method. the splited string can be
accessed using array type (E.g. [0], [1]). Second is replace method used for replace any character
or any word replace method have two arguments first is which you want to replace and second is the
by which want to replace. The third is search method which gives the char position of that substring.

Like 1 Person
Last modified on 29 August 2018
Nikhil Joshi

Nikhil Joshi
Ceo & Founder at Dotnetlovers
Atricles: 135
Questions: 9
Given Best Solutions: 9 *


Sonia Jain
same as in c# ... :D
Like 0 People on 19 June 2013

You are not loggedin, please login or signup to add comments:

Existing User

Login via:

New User