word_mult_delim

Analog of word$ function with multiple delimiters
Or, rather, several single-character delimiters, this way they could be passed in a single string. It could be handy, for example, to get actual words from real-life sentence. Here, all punctuations should be delimiters. Multiple delimiters (like ". ") will be treated as one.

code format = "lb" 'demo aText$="red blue. green,  yellow?! white. black" print "Source text, in '><'" print ">";aText$;"<" print

print "Ordinary JB word$ work:" w$="*" i = 0 while w$<>"" i = i+1 w$=word$(aText$, i)       'multiple delimiters (" ") go as one 'w$=word$(aText$, i, " ")   'multiple delimiters (" ") go as multiple words print i, ">";w$;"<" wend print

print "Replacement for JB word$ work (slow):" w$="*" i = 0 while w$<>"" i = i+1 w$=word2$(aText$, i, " .,;!?")       'multiple delimiters go as one print i, ">";w$;"<" wend

' 'function allow multiple delimiters (like all punctuation and space), 'multiple delimiters (like ". ") will be treated as one

function word2$(aText$, n, delim$) word2$ = "" nWord=0 if n<1 then exit function i = 1 do    'string starts from delimiter? c$=mid$(aText$, i, 1) if instr(delim$, c$) <>0 then 'then skip delimiters till word start while i<=len(aText$) AND instr(delim$, mid$(aText$, i, 1))<>0 i=i+1 wend if i = len(aText$) then exit function  'word not found end if       'else we got word start ws = i

'skip till next delimiter block while i<=len(aText$) AND instr(delim$, mid$(aText$, i, 1))=0 i=i+1 wend

we = i

nWord=nWord+1 if nWord=n then    'found word word2$ = mid$(aText$, ws, we-ws) exit function end if   loop while i<len(aText$)

end function code