udfStrStrip (6)
str udfStrStrip (str, str, int, bln)
;------------------------------------------------------------------------------------------------------------------------------------------
#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
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrEscapeWB (strString)
Return StrReplace (StrReplace (StrReplace (StrReplace (strString, @CRLF, "@CRLF"), @CR, "@CR"), @LF, "@LF"), @TAB, "@TAB")
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


strText = @TAB : "  " : @CRLF : "  " : @CR : "This is the text" : @TAB : "  " : @CRLF : "  " : @CR

strResult11 = udfStrStrip (strText, " "  : @CRLF : @TAB,  0, @FALSE)      ; "|This is the text|"
strResult12 = udfStrStrip (strText, " T" : @CRLF : @TAB,  0, @TRUE)       ; "|his is the text|"
strResult13 = udfStrStrip (strText, " T" : @CRLF : @TAB,  0, @FALSE)      ; "|his is the tex|"

strResult21 = udfStrStrip (strText, " t" : @CRLF : @TAB, -1, @FALSE)      ; "|his is the text@TAB  @CRLF  @CR|"
strResult22 = udfStrStrip (strText, " T" : @CRLF : @TAB,  1, @FALSE)      ; "|@TAB  @CRLF  @CRThis is the tex"
strResult23 = udfStrStrip (strText, " t" : @CRLF : @TAB, -1, @TRUE)       ; "|This is the text@TAB  @CRLF  @CR|"
strResult24 = udfStrStrip (strText, " T" : @CRLF : @TAB,  1, @TRUE)       ; "|@TAB  @CRLF  @CRThis is the text"

strResult31 = udfStrStrip (strText, " exist"  : @CRLF : @TAB, -1, @TRUE)  ; "|This is the text@TAB  @CRLF  @CR|"
strResult32 = udfStrStrip (strText, " exist"  : @CRLF : @TAB, -1, @FALSE) ; "|his is the text@TAB  @CRLF  @CR|"
strResult33 = udfStrStrip (strText, " exist"  : @CRLF : @TAB,  1, @TRUE)  ; "|@TAB  @CRLF  @CRThis is th|"
strResult34 = udfStrStrip (strText, " EXIST"  : @CRLF : @TAB,  1, @FALSE) ; "|@TAB  @CRLF  @CRThis is th|"
strResult35 = udfStrStrip (strText, " exist"  : @CRLF : @TAB,  0, @TRUE)  ; "|This is th|"
strResult36 = udfStrStrip (strText, " exist"  : @CRLF : @TAB,  0, @FALSE) ; "|his is th|"
strResult37 = udfStrStrip (strText, " hexist" : @CRLF : @TAB,  0, @FALSE) ; "||"


strMsgTitle = "Demo udfStrStrip()"
strMsgText = "Text: " : @LF : "|" : udfStrEscapeWB (strText) : "|" : @LF : @LF
strMsgText = strMsgText : "Result11: " : @LF : "|" : udfStrEscapeWB (strResult11) : "|" : @LF
strMsgText = strMsgText : "Result12: " : @LF : "|" : udfStrEscapeWB (strResult12) : "|" : @LF
strMsgText = strMsgText : "Result13: " : @LF : "|" : udfStrEscapeWB (strResult13) : "|" : @LF
strMsgText = strMsgText : @LF
strMsgText = strMsgText : "Result21: " : @LF : "|" : udfStrEscapeWB (strResult21) : "|" : @LF
strMsgText = strMsgText : "Result22: " : @LF : "|" : udfStrEscapeWB (strResult22) : "|" : @LF
strMsgText = strMsgText : "Result23: " : @LF : "|" : udfStrEscapeWB (strResult23) : "|" : @LF
strMsgText = strMsgText : "Result24: " : @LF : "|" : udfStrEscapeWB (strResult24) : "|" : @LF
strMsgText = strMsgText : @LF
strMsgText = strMsgText : "Result31: " : @LF : "|" : udfStrEscapeWB (strResult31) : "|" : @LF
strMsgText = strMsgText : "Result32: " : @LF : "|" : udfStrEscapeWB (strResult32) : "|" : @LF
strMsgText = strMsgText : "Result33: " : @LF : "|" : udfStrEscapeWB (strResult33) : "|" : @LF
strMsgText = strMsgText : "Result34: " : @LF : "|" : udfStrEscapeWB (strResult34) : "|" : @LF
strMsgText = strMsgText : "Result35: " : @LF : "|" : udfStrEscapeWB (strResult35) : "|" : @LF
strMsgText = strMsgText : "Result36: " : @LF : "|" : udfStrEscapeWB (strResult36) : "|" : @LF
strMsgText = strMsgText : "Result37: " : @LF : "|" : udfStrEscapeWB (strResult37) : "|" : @LF

Pause (strMsgTitle, strMsgText)
ClipPut (strMsgTitle : @CRLF : @CRLF : StrReplace (strMsgText, @LF, @CRLF))

:CANCEL
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;   Demo udfStrStrip()
;
;   Text:
;   |@TAB  @CRLF  @CRThis is the text@TAB  @CRLF  @CR|
;
;   Result11:
;   |This is the text|
;   Result12:
;   |his is the text|
;   Result13:
;   |his is the tex|
;
;   Result21:
;   |his is the text@TAB  @CRLF  @CR|
;   Result22:
;   |@TAB  @CRLF  @CRThis is the tex|
;   Result23:
;   |This is the text@TAB  @CRLF  @CR|
;   Result24:
;   |@TAB  @CRLF  @CRThis is the text|
;
;   Result31:
;   |This is the text@TAB  @CRLF  @CR|
;   Result32:
;   |his is the text@TAB  @CRLF  @CR|
;   Result33:
;   |@TAB  @CRLF  @CRThis is th|
;   Result34:
;   |@TAB  @CRLF  @CRThis is th|
;   Result35:
;   |This is th|
;   Result36:
;   |his is th|
;   Result37:
;   ||
;------------------------------------------------------------------------------------------------------------------------------------------