[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]

the end of either string is reached. All other things being equal, the shorter string is considered less than the longer string. Leading or trailing blanks ARE significant.

Regardless of the data types, at the end of all comparisons you get an integer result. This is true even if both operands are strings. Because of this a comparison of two string operands can be used as an operand in performing calculations. The result will be - 1 or 0 (true or false) and can be used as anything but a divisor since division by zero is illegal.


Expressions are treated as if an implied "<>0" follows them. This means that if an expression is true then the next BASIC statements on. the same program line are executed. If the expression is false the rest of the line is ignored and the next line in the program is executed.

Just as with numbers, you can also perform operations on string variables. The only string arithmetic operator recognized by CBM BASIC is the plus sign (+) which is used to perform concatenation of strings. When strings are concatenated, the string on the right of the plus sign is appended to the string on the left, forming a third string as a result. The result can be printed immediately, used in a comparison, or assigned to a variable name. If a string data item is compared with (or set equal to) a numeric item, or vice-versa, the BASIC error message ?TYPE MISMATCH will occur. Some examples of string expressions and concatenation are:

   10 A$="FILE": B$="NAME"
   20 NAM$=A$+B$                      (gives the string: FILENAME)
   30 RES$="NEW "+A$+B$               (gives the string: NEW FILENAME)
               |       +-----------------+
               +-------+ Note space here.|

[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated November 14, 1998.