Advertisement
jargon

trk_

Mar 20th, 2021
3,087
0
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.         offset+=len(delimiter)-1
  43.     loop
  44.    
  45.     if len(buffer)>0 and offset=0 then
  46.         count+=1
  47.         if count>ubound(tok,1) then
  48.             redim preserve tok(0 to count+section)
  49.         end if
  50.        
  51.         tok(count)=buffer
  52.         buffer=space(0)
  53.        
  54.     end if
  55.    
  56.     redim preserve tok(0 to count)
  57.    
  58. end sub
  59.  
  60. sub striptok (subject as string="", delimiter as string=comma, skip as string="", byref buffer as string="")
  61.     redim as string tok()
  62.     trk_tok subject,delimiter,tok()
  63.     dim as integer token_index=0, buffer_index=0
  64.    
  65.     if ubound(tok,1)<1 then
  66.         exit sub
  67.     end if
  68.    
  69.     buffer=space(0)
  70.    
  71.     for token_index=1 to ubound(tok,1)
  72.         if not(tok(token_index)=skip) then
  73.             if len(buffer)>0 then
  74.                 buffer+=delimiter
  75.             end if
  76.             buffer+=tok(token_index)
  77.         end if
  78.     next token_index
  79.  
  80. end sub
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement