DPARSE, DPARSE.CSV |
![]() ![]() ![]() |
The DPARSE splits the elements of a delimited string into other variables. DPARSE.CSV is similar but unquotes strings according to the rules in the CSV standard.
Format
DPARSE string, delimiter, var1, var2,... DPARSE.CSV string, delimiter, var1, var2,...
where
The DPARSE statement extracts successive elements delimited by delimiter within string into the listed variables. A statement such as DPARSE S, ",", A, B, C is equivalent to A = FIELD(S, ",", 1) B = FIELD(S, ",", 2) C = FIELD(S, ",", 3)
DPARSE.CSV extends this action by removing quotes that have been applied to meet the CSV standard. CSV format allows optional double quotes around items and specifies that these must be present when the item contains the delimiting character or a double quote. In the latter case, the embedded double quote will be represented by two adjacent double quotes.
Examples
LOOP READSEQ LINE FROM SEQ.F ELSE EXIT STOCK.REC = "" DPARSE LINE, ",", PART.NO, STOCK.REC<1>, STOCK.REC<2> ...Processing... REPEAT
This loop dismantles a comma separated string to extract three elements.
S = 'abc,"de""f"' DPARSE S, ',', A, B DISPLAY A,B DPARSE.CSV S, ',', A, B DISPLAY A,B
This program will print abc "de""f" abc def showing the difference between the DPARSE and DPARSE.CSV statements. |