Code: Select all
10 rem simple search string example
20 dim r$(1): rem for reporting, messages below
30 r$(0)="no string found"
40 r$(1)="string found from index"
50 s$="abcdefghijklmnopqrstuvwxyz": rem string to search
60 i=1: rem index counter
70 a$="1": rem search condition
80 s=len(s$): rem length of string to search
90 a=len(a$): rem length of search condition
100 rem loop marker
110 if mid$(s$, i, a)<>a$ and i<s then i=i+1: goto 100
120 r=abs(mid$(s$, i, a)=a$): rem turns the true value into 1 for true and 0 for false, like C
130 print r$(r);:if r then print i
At the moment, no string will be found: try changing the condition in line 70 to a$="x" or a$="def" for instance. It will search for exact patterns as specified. The number it returns will say where the string starts from, so if you search for z then the variable i should be 26, or if you search for y then it should be 25 - that's the same if you search for yz.
I'm sure there are better examples.
Regards,
Shaun.