sequent

sequent$ function
This function could save you lot's of processing time if you split long strings with word$ (that is, //parse//). (**!But it only works if you need these words SEQUENTIALLY, one by one!**)

Original post on LB forum: [|Much faster than word$], Mar 7th, 2009 by wallgod In his own words: > //This function, sequent$, is like the word$ command except a lot faster for processing huge strings (i.e. entire files with lines separated by chr$(10)+chr$(13), or any separating string). It uses INSTR and a global variable called 'fjump' which tells it the starting point in INSTR.//

> //With traditional methods of performing this type of operation, the starting position is reset every time you call the function to perform a repetative task on the same string, but now with this method, the function remembers the position it was at last, and resumes reading from there, thus saving a lot of time.//

> //As long as you are starting at the beginning of the string and moving along to any subsequent point in the same string, this is the fastest way I know of to go about it. If you want to start over on a new string, all you have to do is reset the 'fjump' value to 0.//

> //I hope this is useful for somebody. Feedback is welcomed.//

Example code based on that post. Function taken verbatim from that post (with modification by Brad Moore). code format="lb" 'ex. 1. If we know how many words we have - for loop for x=1 to 5 print "'";sequent$("Hello, how are you doing?", x, " ", fjump);"'" next x

print

'ex. 2. If we do not know how many words we have - while loop text$ = "I am doing very well, thank you." sep$ = " " fjump=0:x=0 do x=x+1 print "'";sequent$(text$, x, sep$, fjump);"'" loop until instr(text$, sep$, fjump)=0

function sequent$(var$, n, d$, byref fjump) if n>1 then i1=instr(var$,d$,fjump) if i1=0 then exit function fjump=i1+len(d$) end if   i2=instr(var$,d$,fjump) if i2<>0 then sequent$=mid$(var$,fjump,i2-fjump) else sequent$=mid$(var$,fjump) '  '   0.1 created by wallgod@hotmail.com '  0.2 update by Brad: fjump shared with byref instead of using GLOBAL statement '  ................................................................ '   var$ = source string, n = element to extract, d$ = delimter '  fjump = tracking variable for the function (pass zero first) '  end function

code