Please enable JavaScript to view this site.

A-Shell Reference

Reviewed and Revised December 2023

ASB provides a convenience operator used to assign elements to an array in a single operation from a CSV-formatted string:

a() = <string-expr>

Where:

a() is a DIMX array

<string-expr> is a string expression in a CSV compatible format.

The operation follows the same general rules as INPUT CSV into an array, i.e. the array elements can be fixed length or dynamic elements and the array extent can be fixed or auto_extend. In the case of an auto_extend array, the extent will be reset for each assignment statement. Likewise, the string expression can have comma, tab or pipe delimiters and may contain quoted elements; leading and trailing spaces are trimmed.

Example

dimx a(0), s, 0, auto_extend

a() = "red,green,blue"

a() = "Golden Retriever | Doberman | German Shepard | Chihuahua"

 

The first assignment would result in an array with an extent of 3:  a(1) = "red";  a(2) = "blue";  a(3) = "green". The second assignment would result in an array of an extent of 4:  a(1) = Golden Retriever";  a(2) = "Doberman";  a(3) = "German Shepherd"; a(4) = "Chihuahua".

Comments

Note that for maximum generality, the array should be of type S,0 with the auto_extend flag.  However, if you know the source expression consists only of numbers or of fields of a limited length,  you can adjust the array declaration to be use a more specific type or size.

If the array is not declared with the auto_extend flag and there are more fields in the expression than elements in the array, the additional fields will be ignored.

History

2023 September, A-Shell 6.5.1741: The CSV assignment convenience operator (see 6.5.1739.0) now recognizes the delimiter set via MX_CSVDELIMxs.

2023 August, A-Shell 6.5.1739:  Feature added to A-Shell.