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

Further readings
Declaring Fixed and Dynamic size array in ASP
Getting size of an array
Creating arrays by splitting string using split() function
Joining elements of an array to create a string variable
Searching inside array elements for matching string using Filter
 
Scripts
PHP
JavaScript
All ASP Tutorials
Popular Tutorials
Managing two drop downs
ASP Tutorials
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.