Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '[?] "trk_tok" is supposed to turn subject into a single dimensional string array
- '[?] entry 0 being the original subject
- '[?] entry 1 thru ubound being the tokens from subject as separated by the "delimiter" string.
- '[?] "comma" requires: const comma=","
- declare sub trk_tok(subject as string="", delimiter as string=comma, tok(any) as string, section as long=1024)
- declare sub striptok (subject as string="", delimiter as string=comma, skip as string="", byref buffer as string="")
- sub trk_tok(subject as string="", delimiter as string=comma, tok(any) as string, section as long=1024)
- if len(delimiter)=0 or len(subject)=0 then
- redim tok(0 to 1)
- tok(0)=subject
- tok(1)=subject
- exit sub
- end if
- dim as long offset=0,count=0
- dim as string buffer
- buffer=subject
- redim tok(0 to section)
- tok(0)=subject
- do while offset<len(subject)-len(delimiter)
- buffer=right(buffer,len(buffer)-offset)
- offset=instr(1,buffer,delimiter)
- if offset=0 then
- exit do
- end if
- count+=1
- if count>ubound(tok,1) then
- redim preserve tok(0 to count+section)
- end if
- tok(count)=left(buffer,offset-1)
- offset+=len(delimiter)-1
- loop
- if len(buffer)>0 and offset=0 then
- count+=1
- if count>ubound(tok,1) then
- redim preserve tok(0 to count+section)
- end if
- tok(count)=buffer
- buffer=space(0)
- end if
- redim preserve tok(0 to count)
- end sub
- sub striptok (subject as string="", delimiter as string=comma, skip as string="", byref buffer as string="")
- redim as string tok()
- trk_tok subject,delimiter,tok()
- dim as integer token_index=0, buffer_index=0
- if ubound(tok,1)<1 then
- exit sub
- end if
- buffer=space(0)
- for token_index=1 to ubound(tok,1)
- if not(tok(token_index)=skip) then
- if len(buffer)>0 then
- buffer+=delimiter
- end if
- buffer+=tok(token_index)
- end if
- next token_index
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement