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

Number of User Comments : 1





bobby

23-04-2016

Well, after split, then how to store that result to database? I mean in MS Access..
| ID | Name |
|----|----------|
| 1 | Welcome |
| 2 | to |
| 3 | plus2net, learn web programming and design|

cause everytime i tried, it becomes comma separated values in one row

Post your comments , suggestion , error , requirements etc here .




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2019 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer