Sinclair QL Beginner's Manual page 69

Hide thumbs Also See for QL:
Table of Contents

Advertisement

CHAPTER 11 – HANDLING TEXT – STRINGS
You have used string variables to store character strings and you know that the rules for manipulating
string variables or string constants are not the same as those for numeric variables or numeric
constants. SuperBASIC offers a full range of facilities for manipulating character strings effectively. In
particular the concept of string-slicing both extends and simplifies the business of handling substrings
or slices of a string.
ASSIGNING STRINGS
Storage for string variables is allocated as it is required by a program. For example, the lines:
100 LET words$ = "LONG"
110 LET words$ = "LONGER"
120 PRINT words$
would cause the six letter word, LONGER, to be printed. The first line would cause space for four
letters to be allocated but this allocation would be overruled by the second line which requires space
for six characters.
It is, however, possible to dimension (i.e. reserve space for) a string variable, in which case the
maximum length becomes defined, and the variable behaves as an array.
JOINING STRINGS
You may wish to construct records in data processing from a number of sources. Suppose, for
example, that you are a teacher and you want to store a set of three marks for each student in
Literature, History and Geography. The marks are held in variables as shown:
Lit$
As part of student record keeping you may wish to combine the three string values into one six-
character string called mark$. You simply write:
LET mark$ = lit$ & hist$ & geog$
You have created a further variable as shown:
But remember that you are dealing with a character string which happens to contain number
characters rather than an actual number. Note that in SuperBASIC the & symbol is used to join strings
together whereas in some other BASICs, the + symbol is used for that purpose.
COPY A STRING SLICE
A string slice is part of a string. It may be anything from a single character to the whole string. In order
to identify the string slice you need to know the positions of the required characters.
Suppose you are constructing a children's game in which they have to recognise a word hidden in a
jumble of letters. Each letter has an internal number - an index - corresponding to its position in the
string. Suppose the whole string is stored in the variable jumble$ and the clue is Big cat.
62
Hist$
mark$
56
Geog$
625671
71

Advertisement

Table of Contents
loading

Table of Contents