ARRAY FUNCTIONS IN VBSCRIPT

Array Functions:

1.       Array- returns a variant containing an array.
Syntax: Array(arglist)
Arglist- Required. A list (separated by commas) of values that is the elements in the array
Example:
a=Array(5,10,15,20)
response.write(a(3))
Output:
20
2.       Filter- returns a zero-based array that contains a subset of a string array based on a filter criteria.
Syntax: Filter(inputstrings,value[,include[,compare]])
Inputstrings- Required. A one-dimensional array of strings to be searched
Value- Required. The string to search for
Include- Optional. A Boolean value that indicates whether to return the substrings that include or exclude value. True returns the subset of the array that contains value as a substring. False returns the subset of the array that does not contain value as a substring. Default is True.
             Compare- Optional. Specifies the string comparison to use.
        Can have one of the following values:
  •       0 = vbBinaryCompare - Perform a binary comparison
  •       1 = vbTextCompare - Perform a textual comparison

Example:
a=Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
b=Filter(a,"S")
for each x in b
    response.write(x & "<br />")
next
Output:
Sunday
Saturday
3.       IsArray- returns a Boolean value that indicates whether a specified variable is an array. If the variable is an array, it returns True, otherwise, it returns False.
Syntax: IsArray(variable)
Example:
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
response.write(IsArray(days))
Output:
True
4.       Join- returns a string that consists of a number of substrings in an array.
Syntax:Join(list[,delimiter])
List- Required. A one-dimensional array that contains the substrings to be joined
Delimiter- Optional. The character(s) used to separate the substrings in the returned string. Default is the space character
Example:
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
response.write(Join(days) & "<br />")
response.write(Join(days,",") & "<br />")
response.write(Join(days," ### "))
Output:
       Sun Mon Tue Wed Thu Fri Sat
       Sun,Mon,Tue,Wed,Thu,Fri,Sat
       Sun ### Mon ### Tue ### Wed ### Thu ### Fri ### Sat
5.  LBound- returns the smallest subscript for the indicated dimension of an array.
Syntax: LBound(arrayname[,dimension])
Arrayname- Required. The name of the array variable
Dimension- Optional. Which dimension's lower bound to return. 1 = first dimension, 2 = second dimension, and so on. Default is 1
Example:
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
response.write(LBound(days) & "<br />")
response.write(UBound(days) & "<br />")
Output:
0
6
6.  Split- returns a zero-based, one-dimensional array that contains a specified number of substrings.
Syntax: Split(expression[,delimiter[,count[,compare]]])
Expression- Required. A string expression that contains substrings and delimiters
Delimiter- Optional. A string character used to identify substring limits. Default is the space character
Count- Optional. The number of substrings to be returned. -1 indicates that all substrings are returned
          Compare- Optional. Specifies the string comparison to use.
          Can have one of the following values:
  •      0 = vbBinaryCompare - Perform a binary comparison
  •      1 = vbTextCompare - Perform a textual comparison

Example:
a=Split(“google is my favourite search engine")
for each x in a
    response.write(x & "<br />")
next
Output:
google
is
my
favourite
search
engine
7.    UBound- returns the largest subscript for the indicated dimension of an array.
Syntax:
UBound(arrayname[,dimension])

Arrayname- Optional. Which dimension's upper bound to return. 1 = first dimension, 2 = second dimension, and so on. Default is 1

Dimension- Required. The name of the array variable

Example:
days=Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat")
response.write(LBound(days) & "<br />")
response.write(UBound(days) & "<br />")

Output:

0
6





No comments:

Post a Comment