Using the split() function to create arrays
The built-in split()
function can parse any string into elements of an array.The split(string, arr, fs)
function splits the string value of str
into fields and stores them in thearr
array. The number of fields produced is returned as the value of the split
function. The string value of the third argument, fs
, determines the field separator.The syntax of split()
functions is as follows, followed by a listed explanation of the elements involved:
n = split (str, arr, fs)
str
: This is the input string to be parsed into the elements of the namedarr
.arr
: This is the name of the array.fs
: This is the separator character based on which the array elements are split. If the separator is not given, the elements are split based on thefs
as the separator. The separator can be a single character of the regular expression.n
: This is the index of the array, starting at1
and going up ton
.
The following example illustrates the basic usage of split
to create an...