DPARSE and DPARSE.CSV

DPARSE, DPARSE.CSV

Top  Previous  Next

 

The DPARSE statement 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

 

stringevaluates to the string to be processed.

 

delimiterevaluates to the substring delimiter. If this is more than one character, only the first character is used.

 

var1,var2,...is a list of variables to receive the elements extracted from string. These may be simple variables, matrix elements or field, value or subvalue references.

 

 

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       de"f

showing the difference between the DPARSE and DPARSE.CSV statements.