A string can be created which consists of a series of copies of another string
using STRING$:
10 MODE 135
20 INPUT "What is your string " ,text$
30 copy$=STRING$(10,text$)
40 PRINT "A string containing 10 copies Looks Iike this:"
50 PRINT copy$
INSTR is used to check for the first occurrence of one string within another, for
example:
10 MODE 135
20 INPUT LINE "Ptease type in any sentence",sentence$
30 check=INSTR(sentence$,"e")
40 PRINT "Your sentence contains ";
50 IF check>0 THEN PRINT "an 'e' at position " ;check ELSE PRINT "d
oes not contain an 'e'"
The variable check at line 30 contains the position within sentence$ at which
the first letter e occurs. If sentence$ does not contain an e, check is 0. You can
also search for groups of letters using INSTR. For example replacing line 30
with:
30check=INSTR(sentence$,"the")
makes the program check for the string the within sentence$.
You cannot carry out arithmetic on a string variable, even if that string
variable contains only numeric characters. This can be inconvenient, so there
are two functions which enable you to change a number to a string and vice
versa :
10 MODE 135
20 INPUT "What is today's date (eg 27) ";number
30 number$=STR$(number)
40 INPUT "What month is it ";month$
50date$=month$+" "+number$
60 PRINT "Today's date is ";date$
STR$ in line 30 converts the numeric variable number into a string variable
number$. Lines 50 and 60 are included to demonstrate that the string version
can be concatenated with other strings.
VAL gives the numeric value of a string:
10 MODE 135
20 INPUT "Type in any mixture of numbers and Letters ";mixture$
C 49