53 String variables String variables are used to store ‘strings of characters’ eg words. They can be recognised easily because they always end with a dollar sign. Here are a few examples of string variables containing various strings of characters. Note that these strings must be enclosed by quotation marks. X$ = "HELLO" DAY$ = "SUNDAY 3RD JANUARY" NAME$ = "ALEX" In the first example is called a string variable and HELLO is called a string. Once has been set to contain HELLO we can use statements like PRINT X$ in just the same way as we said earlier. Z = 5 PRINT Z String variables can be used to hold any number of characters between zero (empty) and 255 (full).
X$ = "" will empty X$ = "A" will set to contain one character Of course you cannot use ordinary arithmetic on string variables. For example NAME$ = "SUSAN" PRINT NAME$ / 10 does not make sense. You can’t divide Susan’s name into ten parts. While you can add, subtract, multiply and divide using numeric variables the only similar operation that can be carried out on string variables is that of ‘addition’. Thus 10 A$ = "TODAY IS " 20 B$ = "SUNDAY" 30 C$ = A$ + B$ 40 PRINT C$ >RUN TODAY IS SUNDAY The importance of understanding string variables cannot be over-emphasised. Later chapters develop this idea.