Simulating the STRING$ Function

Author(s): Gene G. Buza
Publication: Synchro-Sette
Pub Details: Synchro-Sette v2 n7 (Volume 2, Issue 7)
Date: August 1983
Pages: 19, 11
Simulating the STRING$ FUNCTION heading with cartoon of a grinning man
Simulating the STRING$ FUNCTION heading with cartoon of a grinning man

One feature not included in Sinclair BASIC that has been sorely missed by me is the STRING$ function. To give you an idea what can be done with this command, let us say that we wanted a line to appear on the screen or in print that had 32 asterisks in a row. We could enter the line:

10 PRINT "********************************"

To achieve this effect over and over again, we could put the asterisks in a string variable such as the following:

10 LET A$ ="********************************"

Now, whenever we want 32 asterisks to appear, we can just tell the computer to PRINT A$.

This is, of course, cumbersome, particularly when we want large amounts of characters. The function format for other computers is as follows:

10 LET A$ = STRING$ (n,c)

Where “n” is the amount of characters you want in the string and “c” is the character’s code number. The character itself can be used as long as it is surrounded by quotation marks. Either of the following lines would produce the same results:

10 PRINT STRING$ (16,38)
10 PRINT STRING$ (16,"A")

If this function were legal on the ZX/TS machines, 16 “A”s in a row would appear on the screen when the program was RUN.

We can achieve this effect, but it requires more program lines. Enter the following program:

  10 REM  SIMULATING THE
STRING$
FUNCTION
20 PRINT ,,"THE STRING FUNCTIO
N IN OTHER COMPUTER BASICS IS
REPRESENTED BY THE FORMULAE -"
,,,"PRINT STRING$(N,C)"
30 PRINT ,,"WHERE",,"N = THE N
UMBER OF CHARACTERS","C = THE CH
ARACTER CODE"
40 PRINT ,,"THIS EFFECT CAN BE
SIMULATED ON THE ZX/TS COMPUTER
S.",,,"PRESS ENTER FOR EXAMPLE :
::"
70 PAUSE 40000
80 CLS
90 SLOW
100 PRINT "ENTER CHARACTER CODE
FROM MANUAL"
110 INPUT C
120 PRINT ,,"HOW MANY CHARACTER
S IN THE STRING?"
130 INPUT N
140 FAST
150 LET A$=""
160 FOR A=1 TO N
170 LET A$=A$+CHR$ C
180 NEXT A
190 CLS
200 PRINT A$
210 PAUSE 40000
220 CLS
230 PRINT "ENTER FIRST MESSAGE
:::"
240 SLOW
260 INPUT B$
270 PRINT ,,"ENTER SECOND MESSA
GE :::"
280 INPUT C$
290 CLS
300 PRINT B$+A$+C$
310 FAST
320 PAUSE 40000
330 CLS
340 RUN

RUN this program and consult the Character Code portion of the User’s Manual. The portion of programs between lines 100 to 200 create the string and display it on the screen. Experiment with “n” values up to 704.

The routine between 230 to 300 takes the string and allows you to input your own message in two parts and have the string separate those two parts. For the first prompt enter “131” and “14” for the second prompt. For the first message prompt, enter “HELLO,” and “HOW ARE YOU?” for the second.

This routine is valuable for creating graphic strings to be used as separating devices when neat printout is required for various documents. Change the following lines to read as follows:

100 PRINT "ENTER CHARACTER(S)"
110 INPUT C$
170 LET A$=A$+C$

You can now enter more than one character at a time for a more dramatic effect by entering the characters themselves. Remember, if two characters are inputted and 10 is the response to the prompt “HOW MANY CHARACTERS IN THE STRING?”, 20 total characters will result.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.