jargon

trk_tok.bas

Mar 20th, 2021
626
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. '[?] "trk_tok" is supposed to turn subject into a single dimensional string array
  3. '[?] entry 0 being the original subject
  4. '[?] entry 1 thru ubound being the tokens from subject as separated by the "delimiter" string.
  5. '[?] "comma" requires: const comma=","
  6.  
  7. declare sub trk_tok(subject as string="", delimiter as string=comma, tok(any) as string, section as long=1024)
  8.  
  9. declare sub striptok (subject as string="", delimiter as string=comma, skip as string="", byref buffer as string="")
  10.  
  11. sub trk_tok(subject as string="", delimiter as string=comma, tok(any) as string, section as long=1024)
  12.  
  13.     if len(delimiter)=0 or len(subject)=0 then
  14.         redim tok(0 to 1)
  15.         tok(0)=subject
  16.         tok(1)=subject
  17.         exit sub
  18.     end if
  19.    
  20.     dim as long offset=0,count=0
  21.     dim as string buffer
  22.     buffer=subject
  23.    
  24.     redim tok(0 to section)
  25.     tok(0)=subject 
  26.    
  27.     do while offset<len(subject)-len(delimiter)
  28.  
  29.         buffer=right(buffer,len(buffer)-offset)
  30.         offset=instr(1,buffer,delimiter)
  31.        
  32.         if offset=0 then
  33.             exit do
  34.         end if
  35.        
  36.         count+=1
  37.         if count>ubound(tok,1) then
  38.             redim preserve tok(0 to count+section)
  39.         end if
  40.        
  41.         tok(count)=left(buffer,offset-1)
  42.     loop
  43.    
  44.     if len(buffer)>0 and offset=0 then
  45.         count+=1
  46.         if count>ubound(tok,1) then
  47.             redim preserve tok(0 to count+section)
  48.         end if
  49.        
  50.         tok(count)=buffer
  51.         buffer=space(0)
  52.        
  53.     end if
  54.    
  55.     redim preserve tok(0 to count)
  56.    
  57. end sub
  58.  
  59. sub striptok (subject as string="", delimiter as string=comma, skip as string="", byref buffer as string="")
  60.     redim as string tok()
  61.     trk_tok subject,delimiter,tok()
  62.     dim as integer token_index=0, buffer_index=0
  63.    
  64.     if ubound(tok,1)<1 then
  65.         exit sub
  66.     end if
  67.    
  68.     buffer=space(0)
  69.    
  70.     for token_index=1 to ubound(tok,1)
  71.         if not(tok(token_index)=skip) then
  72.             if len(buffer)>0 then
  73.                 buffer+=delimiter
  74.             end if
  75.             buffer+=tok(token_index)
  76.         end if
  77.     next token_index
  78.  
  79. end sub
  80.  
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!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×