EasyManuals Logo

Sinclair ZX81 User Manual

Sinclair ZX81
92 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #60 background imageLoading...
Page #60 background image
afterwards as it was before. To make sure this happens, the string that is being assigned to it is cut off on
the right if it is too long, or filled out with spaces if it is too short - this is called Procrustean assignment afte
r
the inn-keeper Procrustes who used to make sure that his guests fitted the bed by either stretching them
out on a rack or cutting their feet off.
If you now try
LET
A$()="COR BLIMEY"
&
PRINT
A$;"."
you will see that the same thing has happened again (this time with spaces put in) because A$() counts as
a substring.
LET
A$="COR BLIMEY"
will do it properly
Slicing may be considered as having priority 12, so, for instance
LEN
"ABCDEF"(2
TO
5) =
LEN
("ABCDEF"(2
TO
5)) = 4
Complicated string expressions will need brackets round them before they can be sliced. For example,
"ABC"+"DEF"(1
TO
2) = "ABCDE"
("ABC"+"DEF")(1
TO
2) = "AB"
Summary
Slicing, using
TO
. Note that this notation is non-standard.
Exercises
1. Some BASICs (not the ZX81 BASIC) have functions called LEFT$, RIGHT$, MID$ & TL$.
LEFT$(A$,N) gives the substring of A$ consisting of the first N characters.
RIGHT$(A$,N) gives the substring of A$ consisting of the characters from the Nth on.
MID$(A$,N1,N2) gives the substring of A$ consisting of N2 characters starting at the N1th.
TL$(A$) gives the substring of A$ consisting of all its characters except the first.
How would you write these in ZX81 BASIC? Would your answers work with strings of length 0 or 1?
2. Try this sequence of commands:
LET
A$="X*+*Y"
LET
A$(2)=
CHR$
11 [the string quote character]
LET
A$(4)=
CHR$
11
PRINT
A$
A$ is now a string with string quotes inside it! So there is nothing to stop you doing this if you are
persevering enough, but clearly if you had
originally typed
LET
A$="X"+"Y"
the part to the right of the equals sign would have been treated as an expression, giving A$ the value "XY".
Now type
LET
B$="X""+""Y"
You will find that although A$ & B$ look the same when printed out, they are not equal - try
PRINT
A$=B$

Other manuals for Sinclair ZX81

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Sinclair ZX81 and is the answer not in the manual?

Sinclair ZX81 Specifications

General IconGeneral
ProcessorZilog Z80A
Processor Speed3.25 MHz
ROM8 KB
InputMembrane keyboard
StorageCassette tape
Power Supply9V DC
Dimensions167 mm x 40 mm x 175 mm
Release Year1981
ManufacturerSinclair Research
Weight350 g
Operating SystemSinclair BASIC
RAM1 KB
PortsTV out, expansion port
DisplayTelevision (RF modulator output)

Related product manuals