Specifications
Concepts - 7
Variables may contain keywords, as long as the keyword is not first. Keywords may be imbedded in variable names. For
example,
GOTOE is not ok
EGOTO is ok
String variables are limited to 255 characters. Arrays may be any length, may be multidimensional, and include strings.
String and array space is limited only by available memory.
Numeric variables take seven bytes of memory. Two bytes for the name, one byte for the length and four bytes for the
value. String variables are stored with a 7–byte header and byte–for–byte as the string was assigned. The header and string
are stored in different locations.
String Variables
CAMBASIC reserves 100 bytes for strings on power–up. Using the CLEAR statement, more or less memory may be
reserved. The reserved memory is shared by all the strings. String constants do not use any of the reserved space. For
example,
10 A$="This is a string constant"
does not use any of the reserved space as the string is a constant.
In the example below, A$ and B$ do not use reserved string space, but C$ does.
10 A$ = "Hello"
20 B$ = "there"
30 C$ = A$+B$
In this example, only B$ uses reserved space.
10 A$ = "Hello"
20 B$ = A$
Strings may be compared using the same relational operators that are used with numbers. The string operators are:
+ Adding or concatenating
= equal
<> not equal
> greater than
< less than
>= greater than or equal
<= less than or equal
Consider the following program:
10 A$ = "ABC"
20 B$ = "ABD"
30 IF A$ > B$ THEN PRINT "YES" : ELSE PRINT "NO"
RUN
NO
Strings are compared on a character–by–character basis. In the example above B$ is greater than A$, as the ASCII value of
D is greater than that of C.