Powered by Blogger.

Thursday, February 27, 2014

Split javascript string

In this article we will discuss about how to split a JavaScript string. Also you can check my previous posts on:

- Identity in sql server 2008

- The App_Code Folder in Asp.Net

- Constructor and Destructors in C#.Net

Here is the string:

var strMainString = new String();

strMainString = "AspDotNetHelp.com|SharePointDotNet.com|EnjoySharePoint.com|Fewlines4Biju.com";

Now we can split the string with separator "|" and we will store in an array.

var arr = new Array();

arr = myString.split("|");

Now we can retrieve the items from the array by using a for loop statement like below:

for(var i=0; i < arr.length; i++)
alert ( arr[i] );