114 24 String handling It has been explained that the BBC Microcomputer can store words or other groups of characters in string variables. There are a number of functions which can be used with strings. For example if A$= "NOTWITHSTANDING" then the string function LEFT$ can be used to copy, say, the left three letters of into another string – . 10 A$="NOTWITHSTANDING" 20 B$=LEFT$(A$,3) 30 PRINT B$ >RUN NOT Similarly MID$ can be used to extract the middle section of a string. Change line 20 thus: 10 A$="NOTHWITHSTANDING" 20 B$=MID$(A$,4,9) 30 PRINT B$ >RUN WITHSTAND Line 20 can be read as ‘ is a copy of the middle of starting at the fourth letter and continuing for nine letters’.
As a result of this flexible use of the word ‘middle’, MID$ can in fact be used to copy any part of a string. Change the program again: 10 A$="NOTWITHSTANDING" 20 B$=MID$(A$,1,7) 30 PRINT B$ >RUN NOTWITH As well as LEFT$ and MID$ there is the string function RIGHT$ which copies the rightmost characters of a string. 10 A$="NOTWITHSTANDING" 20 B$=RIGHT$(A$,4) 30 PRINT B$ >RUN DING