Navigation: thinBasic Modules > Core > String handling > PARSE |
|
Description
Parse a string and extract all delimited fields into an array or matrix.
Syntax
nItems = PARSE (String_Expression, Array, [ANY] Delimiter [, [ANY] FieldsDelim] )
Returns
Number: number of items parsed in String_Expression
Parameters
Name |
Type |
Optional |
Meaning |
StringExpression |
String |
No |
A string expression to parse |
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. |
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 MyArray() As String
Dim nLines As Long
'---This line will dimension and fill MyArray 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", MyArray, ",")
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))
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |