Manually editing a string

Discussions related to database technologies, file handling, directories and storage
Post Reply
Posts: 90
Joined: Tue 15 Oct 2019, 09:10

Manually editing a string

Post by RichardRussell » Wed 04 Dec 2019, 01:07

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.
My posts are moderated; if you are seeing this it has already been approved. If you have a comment about the style or tone of the message please report it to the moderators by clicking the exclamation mark icon rather than complaining on the public forum.

Post Reply