udfArrayVBSplit, udfArrayVBJoin
arr udfArrayVBSplit (str, str, int, int)
str udfArrayVBJoin (arr, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayVBSplit (strExpression, strDelimiter, intCount, intCompare)
objSC = ObjectCreate ("MSScriptControl.ScriptControl")
objSC.Language = "VBScript"
objSC.AddCode(: "Function F(P1,P2,P3,P4)" : @LF : 'F=Split(P1,P2,P3,P4)' : @LF : "End Function")
Return objSC.Run(: "F", strExpression, strDelimiter, intCount, intCompare)
;..........................................................................................................................................
; This UDF udfArrayVBSplit() returns an one-dimensional array containing a specified number of substrings.
;
; Parameter:
; strExpression
;    String expression containing substrings and delimiters.
;    If expression is a zero-length string, then an empty array will be returned, that is, an array with no elements and no data.
; strDelimiter
;    String used to identify substring limits.
;    If delimiter is a zero-length string, then a single-element array containing the entire expression string is returned.
; intCount
;    Number of substrings to be returned; -1 indicates that all substrings are returned.
; intCompare
;    Numeric value indicating the kind of comparison to use when evaluating substrings.
;       0 ... Perform a binary comparison.
;       1 ... Perform a textual comparison.
;..........................................................................................................................................
; (c)Detlev Dalitz.20110608.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfArrayVBJoin (arrArray, strDelimiter)
objSC = ObjectCreate ("MSScriptControl.ScriptControl")
objSC.Language = "VBScript"
objSC.AddCode(: "Function F(P1,P2)" : @LF : 'F=Join(P1,P2)' : @LF : "End Function")
Return objSC.Run(: "F", arrArray, strDelimiter)
;..........................................................................................................................................
; This UDF udfArrayVBJoin() returns a string created by joining a number of substrings contained in an array.
;
; Parameter:
; arrArray
;    One-dimensional array containing substrings to be joined.
; strDelimiter
;    Any string, used to separate the substrings in the returned string.
;    If Delimiter is a zero-length string, then all items in the list are concatenated with no delimiters.
;..........................................................................................................................................
; (c)Detlev Dalitz.20110608.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


DirChange (DirScript ())

; Test Split and Join.

:Test1
strTest1 = "WB|with|VBScript|is|fun!"
arrTest1 = udfArrayVBSplit (strTest1, "|", -1, 1)

ForEach strItem In arrTest1
   Pause ("Test udfArrayVBSplit (1)", strItem)     ; 5 array elements = "WB", "with", "VBScript", "is", "fun!"
Next

strList1 = udfArrayVBJoin (arrTest1, "|")          ; Joined string = "WB|with|VBScript|is|fun!"

Pause ("Test udfArrayVBJoin (1)", strList1)


:Test2
strTest2 = "WB|wisth|VBScrispt|is|fun!"       ; Note: mis-spelling is intended for the test.
arrTest2 = udfArrayVBSplit (strTest2, "Is", -1, 1)

ForEach strItem In arrTest2
   Pause ("Test udfArrayVBSplit (2)", strItem)     ; 4 array elements = "WB|w", "th|VBScr", "pt|", "|fun!"
Next

strList2 = udfArrayVBJoin (arrTest2, "is")         ; Joined string = "WB|wisth|VBScrispt|is|fun!"

Pause ("Test udfArrayVBJoin (2)", strList2)


:Test3
strTest3 = "WB|wisth|VBScrispt|IS|fun!"       ; Note: mis-spelling is intended for the test.
arrTest3 = udfArrayVBSplit (strTest3, "IS", -1, 0)

ForEach strItem In arrTest3
   Pause ("Test udfArrayVBSplit (3)", strItem)     ; 2 array elements = "WB|wisth|VBScrispt|", "|fun!"
Next

strList3 = udfArrayVBJoin (arrTest3, "should be")  ; Joined string = "WB|wisth|VBScrispt|should be|fun!"

Pause ("Test udfArrayVBJoin (3)", strList3)


:Test4
strList4 = udfArrayVBJoin (arrTest1, "")           ; Joined string = "WBwithVBScriptisfun!"

Pause ("Test udfArrayVBJoin (4)", strList4)


:Test5
strList5 = udfArrayVBJoin (arrTest1, " - ")        ; Joined string = "WB - with - VBScript - is - fun!"

Pause ("Test udfArrayVBJoin (5)", strList5)

:CANCEL
Exit