It is basically "trim()" but it runs through the string to trim all the matching alphabet in the string instead of only trimming the matching alphabet at the leftmost side and the rightmost side of the string. I hope this will help somebody.
Note: Edited a little bit. Instead of Select case, if thenis used.
trim.bi
Code: Select all
'a low performance trimmer(maybe?)
#pragma once
'a simple lookup table for ASCII characters
dim shared as string trimset(255)
for i as short = 0 to 255
trimset(i) = chr(i)
next
sub trimInStr(instring as string, byref outstring as string, trimchar as string)
'clears outstring first
outstring = ""
'compare the string: if instring <> trimchar then copy the currently compared
'character to the string
for i as long = 0 to len(instring)-1
if instring[i] <> trimchar[0] then : outstring += trimset(instring[i]) : end if
next
end sub
Here's an example:
Code: Select all
#include "trim.bi"
dim as string outputstr
trimInStr("this is a test", outputstr, " ") ' trims spaces
print outputstr 'should print: "thisisatest"