Unions and arrays
Introduction
Unions and arrays are both first class objects in Unibase. This article describes how to use unions and the additional features available when an array of unions is declared.
Unions
Unions are used to concatenate strings to get a single string.
The declaration for a unions is:
<attribute>, <characters> U <parts>
eg
name, 30 U "Rick" " " "Marshall"
parts ::== <part> {<parts>} part ::== {<attribute>|<text>|<command>} <text> ::== "<characters>" <attribute> ::== [attribute name] <command> ::== `system command`
eg
system, U 50 "now" `date` [system.user]
NB unions are like expressions. They are not stored and therefore cannot be used in an index.
Arrays
One dimensional arrays are defined by following the attribute width by *<array size>
eg
barcodes, 13*10 U ...
To print a union simply quote it as for any other attribute: [name]
It gets more interesting when an array of unions is being printed.
To print and individual element: [barcodes 1]
To print the array as a single string: [barcodes]
To print the array with a join character (which is a separator between elements): [barcodes:J,]
To print the array in csv format: [barcodes:CSV]
To print the array with each element trimmed of trailing spaces: [barcodes:T]
To print the array with trailing spaces replaced by another character: [barcodes:A-]
And you can use any sensible combination of these modifiers.