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

String Manipulation

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

udfStrStrip

 Keywords: RegExp  Regular Expression StrClean String Clean starting trailing characters @CRLF @TAb Spaces

This UDF "udfStrStrip" returns a substring from the given strString.

Depending on whether parameter "intBoundary" is -1 (left edge), 1 (right edge) or 0 (both edges), the leading, trailing, or both leading and trailing occurrences of "strStripChars" will be deleted and the result string will be returned.

Depending on whether parameter "blnMatchCase" is @TRUE or @FALSE, character casing will be respected or not.

;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrStrip (strString, strStripChars, intBoundary, blnMatchCase)
If strString == "" Then Return strString
If strStripChars == "" Then Return strString
intBoundary = Min (Max (intBoundary, -1), 1) ; -1 = Left, 0 = Left+Right, 1 = Right.
objRegExp = ObjectCreate ("VBScript.RegExp")
objRegExp.Global = @TRUE
objRegExp.MultiLine = @FALSE
objRegExp.IgnoreCase = !blnMatchCase
Switch intBoundary
Case -1 ; Strip leading chars.
   objRegExp.Pattern = "^[" : strStripChars : "]+"
   Break
Case 1  ; Strip trailing chars.
   objRegExp.Pattern = "[" : strStripChars : "]+$"
   Break
Case 0  ; Strip leading and trailing chars.
   objRegExp.Pattern = "^[" : strStripChars : "]+|[" : strStripChars : "]+$"
EndSwitch
Return "" : objRegExp.Replace(strString, "")
;..........................................................................................................................................
; This UDF "udfStrStrip" returns a substring from the given strString.
;
; Depending on whether parameter "intBoundary" is -1 (left edge), 1 (right edge) or 0 (both edges),
; the leading, trailing, or both leading and trailing occurrences of "strStripChars"
; will be deleted and the result string will be returned.
;
; Depending on whether parameter "blnMatchCase" is @TRUE or @FALSE,
; character casing will be respected or not.
;..........................................................................................................................................
; Detlev Dalitz.20101222.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


Article ID:   W18397
Filename:   udfStrStrip.txt
File Created: 2010:12:22:08:05:54
Last Updated: 2010:12:22:08:05:54