« Re: FNnxtwrd() TOOL (fixed) »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:03pm

Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Re: FNnxtwrd() TOOL (fixed)  (Read 352 times)
Richard Russell

member is offline


Homepage PM

Posts: 689
xx Re: FNnxtwrd() TOOL (fixed)
« Thread started on: Nov 1st, 2016, 3:59pm »

on Nov 1st, 2016, 01:33am, michael wrote:
I REALLY need a proper tool to interpret my future works

You might be interested in the 'next word' routine that I use in LB Booster:

      Alphabet$ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

      testString$ = "Happy Halloween my fellow programmers!!!"

        word$ = FNword(testString$)
        PRINT word$
      UNTIL word$ = ""

      DEF FNword(RETURN A$)
      LOCAL space$
      space$ = FNtoken(A$, " ")
      = FNtoken(A$,Alphabet$)

      DEF FNtoken(RETURN A$, list$)
      LOCAL T$
      WHILE INSTR(list$, LEFT$(A$,1))
        T$ += LEFT$(A$,1)
        A$ = MID$(A$,2)
      = T$ 

The FNtoken routine returns as much of the supplied string as matches the supplied list of acceptable characters. It is called twice, once to discard leading spaces and then to return the next 'word'. This is quite flexible, for example if you wanted to skip leading tabs as well as spaces ('whitespace') you could do:

      whitespace$ = FNtoken(A$, " "+CHR$(9)) 

and if you want to return a 'variable name' (any letter followed by any combination of letters and numbers) you could do:

      variable$ = FNtoken(A$, Alphabet$) + FNtoken(A$, Alphabet$+"0123456789") 

« Last Edit: Nov 1st, 2016, 6:44pm by Richard Russell » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls