SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Creating arrays by breaking strings using split function

We can break a string and create an array by using split() function in ASP ( VBScript). We can decide what way the array to be created by breaking the string. If we break the string by using one space as a delimiter then the array will contain all words of the string. Same way we can take any other delimiter like coma ( , ) or any other character and generate an array by breaking the string. Here is the syntax of split function.

My_Array=split(My_String," ")

Here My_String is the string variable and we are using one space length as delimiter and breaking the string. We will get our array in the variable My_Array.

We can restrict the total elements of the array by specifying another options parameter to split function. This way the last element will contain rest of the string. This example will make it simple.

My_String="Welcome to plus2net, learn web programming and design"
My_Array=split(My_String," ",3)

Here is the value of each item of the array we get after the split function

My_Array[0] = Welcome
My_Array[1] = to
My_Array[2] = plus2net, learn web programming and design

You can see the last element contains all the words of the string.

Here is the full code

Dim My_String
Dim My_Array
My_String="Welcome to plus2net, learn web programming and design"

My_Array=split(My_String," ")
For Each item In My_Array
Response.Write("<br>" & item)
Next

Same way we can create one string by joining all elements of an array by using Join() function.

Split function in PHP to create an array by breaking a string




Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked


Join Our Email List
Email:  
For Email Newsletters you can trust
Array