70 IF first$>second$ THEN PRINT first$;" is later alphabetically

than " ;second$

80 UNTIL first$="STOP"

Can you see how to stop execution of the program?

The computer can sort a long list of strings into alphabetic order by using string

comparisons like the above. Strictly speaking, the computer compares the

ASCII codes of the characters concerned. A lower-case letter like a is considered

to be greater than the upper-case A because the ASCII code for a is 97 and the

ASCII code for A is only 65.

LEN enables you to find out how many characters there are in a string:

10 MODE 135

20 INPUT "What is your string ";choice$

30 Length=LEN(choice$)

40 PRINT choice$;" contains "; length;" characters. "

The earlier anagram program (see page C37) used LEN to find the length of the

word supplied as input. It then rearranged the characters by combining parts of

the string in a different order. There are several functions which enable you to

copy part of a string:

10 MODE 135

20 example$="Yellow submarine"

30 PRINT "The string is ";example$

40 part1$=LEFT$(example$,4)

50 PRINT "The leftmost 4 Letters are ";part1$

60 part2$=RIGHT$(exampLe$,6)

70 PRINT "The rightmost 6 letters are " :part2$

80 part3$=MID$(example$,5,6)

90 PRINT "The middle 6 characters are ";part3$

100 part4$=MID$(example$,4)

110 PRINT "The characters from the 4th are: ";part4$

LEFT$ and RIGHT$ work in a similar way, by taking the chosen number of

characters from the left or right of the string respectively. MID$ is slightly

different in line 80 it is used to extract letters beginning at the fifth letter and

going on for six letters. In line 100 the second number is omitted, which causes

MID$ to extract all the characters from the fourth to the end of the string.

Needless to say the numbers in each of the examples above may be replaced by

numeric variables.

C 48