More about strings
Strings are merely groups of characters and this section deals with their
manipulation in BBC BASIC.
You can join together (concatenate) several strings simply by telling the
computer to 'add' one string to the end of another:
10 MODE 135
20 first$="The start"
30 second$="and the end. "
40 all$=first$+second$
50 PRINT all$
Running the program gives:
The startand the end.
Other than that the composite string may not exceed 255 characters, there is
effectively no limit on the number of strings which may be joined together at
one time. You could, for example, include an additional space in the line shown
above using:
40 all$=first$+" "+second$
Two strings can also be compared using < = and > (or any combination of the
three). The two strings are compared character by character until a difference
is found. The string containing the character earliest in the alphabet is 'less
than' the other string. For example:
-- PUPPY is less than SHARK because P comes before S;
-- PUPPY is less than RAT because P comes before R;
-- PUPPY is greater than POPPY because both words begin with the letter P
and U comes after O;
-- PUPPY is greater than MONKEY because P comes after M.
If you are still not sure about this, run the following program which lets you
compare pairs of strings:
10 MODE 135
20 REPEAT
30 INPUT LINE "What is the first string", first$
40 INPUT LINE "What is the second string" , second$
50 IF first$<second$ THEN PRINT first$;" is earlier alphabetically
than " ;second$
60 IF first$=second$ THEN PRINT "The two strings are identical."
C 47