PARSE
<< Click to Display Table of Contents >> Navigation: ThinBASIC Core Language > BuiltIn Functions > String functions > PARSE |
Description
Parse a string and extract all delimited fields into an array or matrix.
Syntax
nItems = PARSE ( [FILE] MainString, Array, [ANY] Delimiter [, [ANY] FieldsDelim [, MaxRowToCheckForNField]] )
Returns
Number: number of items parsed in String_Expression
Parameters
Name |
Type |
Optional |
Meaning |
MainString |
String |
No |
A string expression to be parsed
If FILE statement is specified, MainString is considered a file name and will be used to directly load specified file content |
Array |
Variable |
No |
The name of a previously defined array |
Delimiter |
String |
No |
The field delimiter, which may be one or more characters long. If the ANY option is present, each appearance of any single character comprising Delimiter is considered a valid delimiter. |
FieldsDelim |
String |
Yes |
An additional field delimiter used in case String_Expression is a matrix. In this case Array will be re dimensioned to be a matrix. This option will work only if Array is defined AS String. If the ANY option is present, each appearance of any single character comprising FieldDelim is considered a valid delimiter. |
MaxRowToCheckForNField |
Numeric |
Yes |
PARSE function try to determine the number of fields scanning all rows in the quadratic buffer. This is quite time and memory consuming action because the full buffer will be scanned twice. In order to reduce this process, here programmer can indicate the number of rows to consider for determining the number of fields |
Remarks
Array can be both a string array or a numeric array. In case of numeric array, automatic string to number conversion will take place and numbers will be casted to the array numeric data type.
Restrictions
See also
Examples
Script example
'-------------------------------------
'---Array Example
'-------------------------------------
Dim MyMatrix() As String
Dim nLines As Long
'---This line will dimension and fill MyMatrix to be an array of 6 elements
' nLines will contain the number of items parsed, that is 6 in this case
nLines = PARSE("1,2,3,4,5,6", MyMatrix, ",")
MSGBOX 0, "Number of items: " & UBound(MyMatrix(1))
'-------------------------------------
'---Matrix Example
'-------------------------------------
Dim MyMatrix() As String
Dim nLines As Long
'---This line will dimension and fill MyMatrix to be a matrix of 3 rows and 5 colums
' nLines will contain the number of lines parsed, that is 3 in this case
nLines = PARSE("1,2,3,4,5|6,7,8,9,10|A,B,C", MyMatrix, "|", ",")
MSGBOX 0, "Number of lines : " & UBound(MyMatrix(1))
MSGBOX 0, "Number of columns: " & UBound(MyMatrix(2))