Advertisement
jargon

Tim Keal & Mysoft's token overload

Sep 14th, 2020
2,587
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Token fbc routines by Tim Keal & Mysoft
  2.  
  3. declare function token overload (subject as string,sep() as string,index as string="1") as string
  4. declare function token(subject as string,sep as string=",",index as string="1") as string
  5.  
  6. function token overload (subject as string,sep() as string,index as string="1") as string
  7.     dim as string buffer,Ln
  8.     dim as long o,t,i
  9.     dim as long s(lbound(sep,1) to ubound(sep,1))
  10.    
  11.     buffer=subject
  12.     t=0
  13.     i=val(index)
  14.    
  15.     if val(index)>0 then
  16.    
  17.         do
  18.             t=t+1
  19.            
  20.             for n=lbound(sep,1) to ubound(sep,1)
  21.                 s(n)=instr(1,buffer,sep(n))
  22.                 Ln=mid(buffer,o+len(sep(n)))
  23.                 buffer=mid(buffer,o+len(sep(n)))
  24.             next n
  25.            
  26.             for n=lbound(sep,1) to ubound(sep,1)
  27.                 if s(n)<o then
  28.                     o=s(n)
  29.                     d=n
  30.                 end if
  31.             next n
  32.            
  33.             Ln=mid(buffer,o+len(sep(d)))
  34.             buffer=mid(buffer,o+len(sep(d)))
  35.        
  36.         loop until t=val(index)
  37.        
  38.         token=Ln
  39.        
  40.     elseif index="ct" then
  41.        
  42.         do
  43.             t=t+1
  44.            
  45.             for n=lbound(sep,1) to ubound(sep,1)
  46.                 s(n)=instr(1,buffer,sep(n))
  47.             next n
  48.            
  49.             for n=lbound(sep,1) to ubound(sep,1)
  50.                 if s(n)<o then
  51.                     o=s(n)
  52.                     d=n
  53.                 end if
  54.             next n
  55.            
  56.             Ln=mid(buffer,o+len(s(d)))
  57.             buffer=mid(buffer,o+len(s(d)))
  58.  
  59.         loop until o=0
  60.        
  61.         token=str(t)
  62.    
  63.     end if
  64.    
  65. end function
  66.  
  67. function token(subject as string,sep as string=",",index as string="1") as string
  68.   dim as string sTemp(0) : sTemp(0) = sep
  69.   return token(subject,sTemp(),index)
  70. end function
  71.  
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement