In another thread, somebody has enquired how one might go about 'manually' editing the contents of a string variable. There are of course many ways in which this task could be tackled, such as leveraging a Windows textbox using WINLIB5. But it's worth bearing in mind that all versions of BBC BASIC contain a built-in line editor accessible from BASIC code: the INPUT statement! So editing text contained in a string variable can be as simple as this:
Code: Select all
text$ = "The quick brown fox jumps over the lazy dog"
tempfile$ = @tmp$ + "edit.tmp"
F% = OPENOUT(tempfile$)
BPUT #F%, text$;
CLOSE #F%
OSCLI "exec """ + tempfile$ + """"
INPUT LINE "" edited$
PRINT edited$
The string is first written to a temporary file, which is *EXECed; this causes it to be entered into the INPUT statement as if it had been typed by the user. The usual line editing features of the INPUT statement can then be used to modify the string; pressing Enter returns it to the program.
It works in both BB4W and BBCSDL.