2.3.4.2.2. - String Data Arrays
Arrays of type
string
are identical to
byte
arrays in terms
of storage requirements and behavior in most operations.
However, when used as described below,
the string arrays do behave differently.
If a row of a string array represents a number and is used in a conditional expression, then the value of the conditional expression will be the number. For example, the strings
0.00
or
0x000
will evaluate as zero or false in a conditional expression.
In contrast, for number arrays, a conditional evaluates as zero
only if every element of the array is zero.
Functions that take string arguments, such as
on()
, length()
, unix()
, etc., will allow a row of a string array
to be used as an argument.
Use of a number array is invalid and produces an error.
The
print
command will print string arrays as ASCII text,
while byte arrays display each byte as a number.
In assignments to a row of a string array, the right hand side is copied to the byte elements of the string array as a string, even if the right hand side is a number. Any remaining elements of the string array row are set to zero. Thus, the results differ in the assignments below:
string array arr_string[20] arr_string = 3.14159 print arr_string 3.14159 byte array arr_byte[20] arr_byte = 3.14159 print arr_byte {3 <20 repeats>}In the first example, the string representation of the number is copied to the row of the string array, while in the second, each element of the array is assigned the (truncated) value of the number.