Home

Arrays are used to hold data as an array of variables, which can be accessed with their index number.

A String is also an array of characters. However in asp or such high level language we can add/concatenate and search through strings or apply other type of functionality on them very easily.

Arrays and string.

The first example defines an array named myArray and put three value in it. The for loop display them one by one.

In the second example split function is used to breakdown a string into array of words. The split function cuts down a string into words by considering a space " " as a delimiter, any other character or string can also be used as a delimiter . The split function is a very handy function while programming.

The third example is showing how to add two string and other useful string manipulation stuff.

<%
'Example 1
Dim myArray(4) ' Dynamic array of any number of elements.

myArray(0) = "Sunday"
myArray(1) = "Monday"
myArray(2) = "Tuesday"

For i=0 to 2
  response.write i & ")" & myArray(i) & "<br>"
Next
%>

<hr>

<%
'Example 2

myText="Hello My World!"
myArray2=Split(myText, " ")

  response.write myArray2(0) & "<br>"
  response.write myArray2(2) & "<br>"
%>

<hr>

<%
'Example 3
Dim strOne, strTwo

strOne = "Hello,"
strTwo = "How are you."

strThree= strOne & strTwo

Response.write strThree & "<hr>"

'Len() function returns length of string.
Response.write "Length of first String is:" & Len(strOne)

Response.write "<hr>"

'Asc() returns the ascii value of a character
Response.write "Ascii value of A is:" & Asc("a")

Response.write "<hr>"

'Instr() returns the location of first occurance of a string within the input string. Returns 0 if its not found.
Response.write "Location of 'are' in strTwo:" & Instr(strTwo,"are")


%>

[Download Sample Code]