next up previous contents index
Next: Array Overloads Up: Operator Overloading Previous: Operator Overloading   Contents   Index

String Overloads

The operators = = , ! = , > , > = , < , < = have been overloaded for strings. If the two operands are strings, the C strcmp function is invoked to compare the two strings. If either string is null, it is treated as if it has a lexically minimal value. Either operand can be a scalar 0, which is treated as a null string. Thus, forms like if (string == 0) can be used to test for a null string. Null strings, which have no storage, are produced be some script functions. These are different from empty strings, produced for example by string = "", which contain an invisible string termination character.

The + operator has been overloaded for strings to perform concatenation, similar to the Strcat library function. The expression s3 = s1 + s2 is equivalent to s3 = Strcat(s1, s2).

The + and - operators can be applied where the first argument is a string and the second argument is a scalar, and vice-versa in the case of + . The result of the operation is a pointer into the string, which behaves as a string with the first character at the offset given by the scalar. An error is generated if the offset is negative, or is beyond the end of the string.

The - operator can be applied where both operands are strings. The result is a scalar variable representing the difference between the memory addresses of the two strings. This is only useful if both operands are references to the same string.

The ! operator can be applied to strings. The construct is true only if the string variable contains a null string.


next up previous contents index
Next: Array Overloads Up: Operator Overloading Previous: Operator Overloading   Contents   Index
Stephen R. Whiteley 2017-03-22