# Tim Keal's "token" function

Sep 13th, 2020
1,463
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function token(subject as string,sep() as string=",",index as string="1") as string
2.     dim as string buffer,Ln
3.     dim as long o,t,i
4.     dim as long s(lbound(sep,1) to ubound(sep,1))
5.
6.     buffer=subject
7.     t=0
8.     i=val(index)
9.
10.     if val(index)>0 then
11.
12.         do
13.             t=t+1
14.
15.             for n=lbound(sep,1) to ubound(sep,1)
16.                 s(n)=instr(1,buffer,sep(n))
17.                 Ln=mid(buffer,o+len(sep(n)))
18.                 buffer=mid(buffer,o+len(sep(n)))
19.             next n
20.
21.             for n=lbound(sep,1) to ubound(sep,1)
22.                 if s(n)<o then
23.                     o=s(n)
24.                     d=n
25.                 end if
26.             next n
27.
28.             Ln=mid(buffer,o+len(sep(d)))
29.             buffer=mid(buffer,o+len(sep(d)))
30.
31.         loop until t=val(index)
32.
33.         token=Ln
34.
35.     elseif index="ct" then
36.
37.         do
38.             t=t+1
39.
40.             for n=lbound(sep,1) to ubound(sep,1)
41.                 s(n)=instr(1,buffer,sep(n))
42.             next n
43.
44.             for n=lbound(sep,1) to ubound(sep,1)
45.                 if s(n)<o then
46.                     o=s(n)
47.                     d=n
48.                 end if
49.             next n
50.
51.             Ln=mid(buffer,o+len(s(d)))
52.             buffer=mid(buffer,o+len(s(d)))
53.
54.         loop until o=0
55.
56.         token=str(t)
57.
58.     end if
59.
60. end function
RAW Paste Data

# Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!