WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Formatting UDFs

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

StrTrimClean

 Keywords: Trim characters from string 

#DefineFunction strTrimClean(sourcestring, characters, iOption)
   ;------------------------------------------------------------------
   ; Trim characters from string
   ;    characters: string of characers to trim (see strClean(...))
   ;    iOption   : -1=TrimLeft, 1=TrimRight, 0=TrimBoth (thanks Detlev)
   ;
   ; 20101219 Lars M. Doornbos
   ;------------------------------------------------------------------
   ;-- clean leading
   If !iOption || iOption == -1
      While @TRUE
         newstring = StrClean(StrSub(sourcestring, 1, 1), characters, '', @FALSE, 1):StrSub(sourcestring, 2, -1)
         If newstring == sourcestring Then Break
         sourcestring = newstring
      EndWhile
   EndIf
   ;-- clean trailing
   If !iOption || iOption == 1
      While @TRUE
         slen = StrLen(sourcestring)
         newstring = StrSub(sourcestring, 1, slen-1):StrClean(StrSub(sourcestring, slen, 1), characters, '', @FALSE, 1)
         If newstring == sourcestring Then Break
         sourcestring = newstring
      EndWhile
   EndIf
   Return sourcestring
#EndFunction

sourcestring = @TAB:'  ':@CRLF:'  ':@CR:'This is the text':@TAB:'  ':@CRLF:'  ':@CR

result = strTrimClean(sourcestring, ' ':@CR:@TAB:@LF, 0)
Pause('','|':result:'|')

Article ID:   W18371
Filename:   StrTrimClean.txt
File Created: 2010:12:20:09:55:12
Last Updated: 2010:12:20:09:55:12