This topic provides code samples of how to work with arrays.
-
Initializes an array
{ "Monday", "Tuesday", "Wednesday" }
-
Sets the second element in the array
myStringArray(1) = "Friday"
-
Gets the first element in the array
myString = myStringArray(0)
-
Sorts an array in ascending order
Sort(myArray)
-
Calculates the sum of all array elements
Sum()
-
Gets the lowest value in the array
Min()
-
Gets the number of elements in the array
Length
-
Computes the average of all array elements
Average()
-
Splits a string at a single character, in this case whenever when a comma is found and returns an array of strings. If the delimiter is not found, the original string is returned.
mySplittedArray = myString.Split(CChar(","))
-
Splits a string whenever "Thursday" occurs in the string and returns an array of strings. If the delimiter is not found, the original string is returned.
mySplittedArray = myString.Split(New String() { "Thursday" }, StringSplitOptions.None)