Classic ASP Framework
org.classicasp.primitive.ArrayEx

The ArrayEx class lets you access and manipulate arrays. Array indices are zero-based, which means that the first element in the array is (0), the second element is (1), and so on. You can store a wide variety of data types in an array element, including numbers, strings, objects, and even other arrays. This class will accept a JSON encoded array.

To create a ArrayEx object, you can use the constructor or the global function, assign a literal value, or assign a JSON value

Example 1

  Response.Write ArrayEx("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]").reverse().slice(1,5).sort("ASC").toJSON()
  

Example 1 Output

[5,6,7,8,9]

Example 2

  Dim oArray : Set oArray = ArrayEx("[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]")
  oArray(0) = "Value 1"
  Response.Write oArray.toJSON()
  

Example 2 Output

["Value 1",2,3,4,5,6,7,8,9,10]

Summary

Removes empty, Null, and duplicate entries from an array and creates a new array.
Concatenates the elements specified in the parameters with the elements in an array and creates a new array.
Executes a test function on each item in the array and constructs a new array for all items that return true for the specified function.
Executes a function on each item in the array and returns a new array.
Sets the name of each item in the array and returns a new array.
Gets the value of an item in the array.
Gets the number of items in the array.
Gets the core value of the object.
Joins the items in the array using a delimiter.
Gets the length of the array.
Removes the last element from an array and returns the value of that element.
Adds one or more elements to the end of an array and returns the new length of the array.
Returns the elements of an array in reverse order as a new array.
Searches the array for a value and returns a boolean.
Sets the value of an item in the array.
Sets the value of an item in the array, allows the use of a dot (.
Returns a specified number of elements from an array as a new array.
Sorts the array and returns a new array.
Sorts the array by an object name and returns a new array.
Adds up the values in the array.
Converts unicode characters to ascii characters.
Returns a Bencoded string representation of the object.
Escapes special characters in the unescaped_array, so that it is safe to place it in a query.
Converts text to html and encodes special characters in text to html encoding.
Decodes special characters in the object items to html encoding.
Encodes special characters in the object items to html encoding.
Returns a json encoded string representation of the object.
Returns a string representation of the object.
Returns an XML encoded string representation of the object.
Writes a CSV file to the client.
Writes a CSV file.
Writes a json encoded string representation of the object.
Writes an XML encoded string representation of the object.

compact

Public Function compact()
Removes empty, Null, and duplicate entries from an array and creates a new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c', '']").compact().writeJSON()
	  

Output

["a","b","c"]

concat

Public Function concat(ByRef vInputValue)
Concatenates the elements specified in the parameters with the elements in an array and creates a new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").concat("['d', 'e', 'f']").writeJSON()
	  

Output

["a","b","c","d","e","f"]

filter

Public Function filter(ByVal vInputValue)
Executes a test function on each item in the array and constructs a new array for all items that return true for the specified function. If an item returns false, it is not included in the new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").filter("myFuncFilterB").writeJSON()
	  

Output

["a","c"]

forEach

Public Function forEach(ByVal vInputValue)
Executes a function on each item in the array and returns a new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").forEach("myFuncAddPadding").writeJSON()
	  

Output

[" a "," b "," c "]

forEachSetName

Public Function forEachSetName(ByVal vInputValue)
Sets the name of each item in the array and returns a new array.

Returns

ArrayEx

getItem

Public Function getItem(ByVal sInputName)
Gets the value of an item in the array.

Returns

Variant

getItemCount

Public Function getItemCount()
Gets the number of items in the array.

Returns

NumberEx

getItems

Public Function getItems()
Gets the core value of the object.

Returns

ArrayEx

joinEx

Public Function joinEx(ByVal sInputDelimiter)
Joins the items in the array using a delimiter.

Returns

StringEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").joinEx("-").writeJSON()
	  

Output

"a-b-c"

length

Public Function length()
Gets the length of the array.

Returns

NumberEx

pop

Public Function pop()
Removes the last element from an array and returns the value of that element.

Returns

Variant

Example

		
	  Call ArrayEx("['a', 'b', 'c']").pop().writeJSON()
	  

Output

"c"

push

Public Function push(ByRef vInputValue)
Adds one or more elements to the end of an array and returns the new length of the array.

Returns

NumberEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").push('d').writeJSON()
	  

Output

["a","b","c","d"]

reverse

Public Function reverse()
Returns the elements of an array in reverse order as a new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").reverse().writeJSON()
	  

Output

["c","b","a"]

search

Public Function search(
ByVal vInputFind,
ByVal bInputMatchExact)
Searches the array for a value and returns a boolean.

Returns

BooleanEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").search("a", True).writeJSON()
	  

Output

True

setItem

Public Sub setItem(
ByVal sInputName,
ByRef vInputValue)
Sets the value of an item in the array.

Returns

N/A

setItemEx

Public Sub setItemEx(
ByVal sInputName,
ByRef vInputValue)
Sets the value of an item in the array, allows the use of a dot (.) to set subfields.

Returns

N/A

slice

Public Function slice(
ByVal lInputIndexStart,
ByVal lInputIndexEnd)
Returns a specified number of elements from an array as a new array.

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").slice(0,1).writeJSON()
	  

Output

["a","b"]

sort

Public Function sort(ByVal vInputValueOrder)
Sorts the array and returns a new array. (ASC, DESC, RAND)

Returns

ArrayEx

Example

		
	  Call ArrayEx("['a', 'b', 'c']").sort("DESC").writeJSON()
	  

Output

["c","b","a"]

sortOn

Public Function sortOn(
ByVal vInputValueName,
ByVal vInputValueOrder)
Sorts the array by an object name and returns a new array. (ASC, DESC, RAND)

Returns

ArrayEx

Example

		
	  Call ArrayEx("[{'name':'a'}, {'name':'b'}, {'name':'c'}]").sortOn("name", DESC").writeJSON()
	  

Output

[{"name":"c"},{"name":"b"},{"name":"a"}]

sum

Public Function sum()
Adds up the values in the array.

Returns

StringEx

toAscii

Public Function toAscii()
Converts unicode characters to ascii characters.

Returns

ArrayEx

toBencode

Public Function toBencode()
Returns a Bencoded string representation of the object.

Returns

String

Example

	
	  Response.Write ArrayEx("['a', 'b', 'c']").toBencode()
	  

Output

l1:a1:b1:ce

toEscapeSql

Public Function toEscapeSql()
Escapes special characters in the unescaped_array, so that it is safe to place it in a query.

Returns

ArrayEx

toHtml

Public Function toHtml()
Converts text to html and encodes special characters in text to html encoding.

Returns

ArrayEx

toHtmlDecode

Public Function toHtmlDecode()
Decodes special characters in the object items to html encoding.

Returns

ArrayEx

toHtmlEncode

Public Function toHtmlEncode()
Encodes special characters in the object items to html encoding.

Returns

ArrayEx

toJSON

Public Function toJSON()
Returns a json encoded string representation of the object.

Returns

String

Example

		
	  Response.Write ArrayEx("['a', 'b', 'c']").toJSON()
	  

Output

["a","b","c"]

toString

Public Function toString()
Returns a string representation of the object.

Returns

StringEx

toXML

Public Function toXML()
Returns an XML encoded string representation of the object.

Returns

String

Example

		
	  Response.Write ArrayEx("['a', 'b', 'c']").toXML()
	  

Output

<data type="Array" length="2"><data type="String">a</data><data type="String">b</data><data type="String">c</data></data>

writeCsv

Public Sub writeCsv(ByVal sFileName)
Writes a CSV file to the client.

Returns

N/A

writeCsvToFile

Public Function writeCsvToFile(ByVal sFilePath)
Writes a CSV file.

Returns

N/A

writeJSON

Public Sub writeJSON()
Writes a json encoded string representation of the object.

Returns

N/A

Example

		
	  Call ArrayEx("['a', 'b', 'c']").writeJSON()
	  

Output

["a","b","c"]

writeXML

Public Sub writeXML()
Writes an XML encoded string representation of the object.

Returns

N/A

Example

		
	  Call ArrayEx("['a', 'b', 'c']").writeXML()
	  

Output

<data type="Array" length="2"><data type="String">a</data><data type="String">b</data><data type="String">c</data></data>

'***ClassicASP.org
'Copyright 2010 ClassicASP.org

'This file is part of ClassicASP Framework.

'ClassicASP-Framework is free software: you can redistribute it and/or modify
'it under the terms of the GNU General Public License as published by
'the Free Software Foundation, version 3 of the License.

'ClassicASP-Framework is distributed in the hope that it will be useful,
'but WITHOUT ANY WARRANTY; without even the implied warranty of
'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
'GNU General Public License for more details.

'You should have received a copy of the GNU General Public License
'along with ClassicASP-Framework. If not, see .

'For additional information please visit .