User`s manual

5-12
Coding/Decoding Program
5 CLS: PRINT CHR$(23)
10 CLEAR 1000
20 INPUT "ENTER MESSAGE"; M$
30 FOR K=1 TO LEN(M$)
40 T$=MID$(M$, K, 1 )
60 CD=ASC(T$)+5: IF CD>255 CD=CD-255
70 NU$=NU$ + CHR$(CD)
80 NEXT
90 PRINT "THE CODED MESSAGE IS"
100 PRINT NU$
110 FOR K=1 TO LEN(NU$)
120 T$=MID$(NU$, K, 1)
130 CD=ASC(T$)-5: IF CD < 0 CD=CD+255
140 OLDS=OLD$+CHR$(CD)
150 NEXT
160 PRINT "THE DECODED MESSAGE IS"
170 PRINT OLD$
RUN the program.
Lines 30-80 and 110-150 demonstrate how you can "peel off"' the characters
of a string for examination. Lines 60 and 130 demonstrate manipulation of
ASCII codes.
Instring Subroutine
Using the intrinsic string functions MID$ and LEN, it's easy to create a very
handy string-handling subroutine, INSTRING. This function takes two string
arguments and tests to see whether one is contained in the other. When you
are searching for a particular word, phrase or piece of data in a larger body of
text or data, INSTRING can be very powerful. Here's the subroutine:
999 END 'THIS IS A PROTECTIVE END-BLOCK
1000 FOR I=1 TO LEN(X$)-LEN(Y$)+1
1010 IF Y$=MID$(X$,I,LEN(Y$)) RETURN
1020 NEXT: I=0 : RETURN
To use the subroutine, first assign the value of the larger string (the "search
area") to X$, and the value of the desired substring to Y$. Then call the
subroutine with GOSUB. The subroutine will return a value of I which tells
you the starting position of Y$ in the larger string X$; or if Y$ is not a
substring of X$, I is returned with a value of zero.