A string is a data literal delimited by an opening and closing delimiter character. A string can contain any character, except the delimiter character itself. For this reason, MVBasic supports three alternative delimiter characters:
The double quote character (") is most commonly used to delimit a string. It permits the inclusion of single quotes and apostrophes (') within the string, the inclusion of the backslash, and is compatible with other programming languages. For example: "Tom's string of data"
The single quote character (') can be used to delimit a string. It permits the inclusion of double quotes within the string, the inclusion of the backslash, and is compatible with SQL code. For example: 'His "important" data'
The backslash character (\) can be used to delimit a string. It permits the inclusion of both double quotes and single quotes within the string. It is not compatible with other programming languages. For example: \Tom's "important" data\
Strings with these three types of delimiters may be freely mixed. For example, it is possible to concatenate strings with different delimiters, as shown in the following example: 'His "important" data':" isn't very important".
A string is a literal, and is not parsed. The exception to this is when a string is being input as a numeric value.
Strings and Numerics
By default, Caché MVBasic converts numeric strings to numeric and boolean values using the ObjectScript conventions. To perform these conversions using PICK mode conventions (used by all MultiValue system emulation modes) specify $OPTIONS PICK.CONVERT.
An empty string in Caché is either converted to a numeric/boolean value of 0, or treated a string of zero length, depending on the function. In PICK.CONVERT mode an empty string is always converted to 0.
A numeric string is a string that contains only numeric characters (the number 0 through 9, a single leading plus or minus sign, the decimal point delimiter, and the letter E used for scientific notation). It may include leading or trailing zeros. A numeric string is always accepted as a numeric. Thus "123.4" is identical to 123.4. In this conversion, a leading plus sign and leading and trailing zeros are removed, and the decimal point is removed if not followed by a fractional value. In Caché mode, multiple leading plus and minus signs are permitted and evaluated. In PICK mode, only a single leading plus or minus sign is evaluated; multiple signs are treated as a mixed numeric string.
A mixed numeric string is a string that contains both numeric and non-numeric characters, with the first character (or characters) in the string being numeric. For example: "7 dwarves" or "12.5 kilometers". The treatment of mixed numeric strings is very different in Caché mode and PICK mode. In Caché mode, the numeric is parsed until the first non-numeric character is encountered. Thus "12.5 kilometers" is parsed as 12.5. The boolean value of a mixed numeric string simply depends on whether the resulting number is zero or non-zero. In PICK mode, a mixed numeric string is never parsed for its numeric value. When a number is expected, a mixed numeric string is always evaluated as 0, and frequently generates an error. When converted to a boolean, a mixed numeric string always returns True, because any string is a non-zero value.
The following examples demonstrate the numeric conversion differences between Caché mode and PICK mode:
;! Cache Mode PRINT "" + 3 ;! returns 3 PRINT "+007" + 3 ;! returns 10 PRINT "--7" + 3 ;! returns 10 PRINT "7dwarves" + 3 ;! returns 10
;! PICK Mode $OPTIONS PICK.CONVERT PRINT "" + 3 ;! returns 3 PRINT "+007" + 3 ;! returns 10 PRINT "--7" + 3 ;! returns 3 PRINT "7dwarves" + 3 ;! returns 3