udfStrArrayize (2)
arr udfStrArrayize (str)
;----------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrArrayize2 (strString)
If strString == "" Then Return ArrDimension (0) ; Return a valid empty dim-0 array with no elements.
For intI = 1 To 255
   strDelimiter = Num2Char (intI)
   If !StrScan (strString, strDelimiter, 1, @FWDSCAN)
      objRegExp = ObjectCreate ("VBScript.RegExp")
      objRegExp.IgnoreCase = @FALSE
      objRegExp.MultiLine = @FALSE
      objRegExp.Global = @TRUE
      objRegExp.Pattern = ""
      strOut = objRegExp.Replace(strString, strDelimiter)
      objRegExp.Pattern = "^" : strDelimiter : "|" : strDelimiter : "$"
      Return Arrayize (objRegExp.Replace(strOut, ""), strDelimiter)
   EndIf
Next
Return ArrDimension (0) ; Cannot split this string. Return a valid empty dim-0 array with no elements.
;......................................................................................................................
; This UDF udfStrArrayize returns a dim-1 array, whose elements are filled with the successive
; characters of the given input string (one char = one element).
;
; Example: "string" ==> ["s"|"t"|"r"|"i"|"n"|"g"]
;
; If the given input string is empty or cannot be arrayized, then the UDF returns a dim-0 array with no element.
;
; Detlev Dalitz.20090627.
;......................................................................................................................
#EndFunction
;----------------------------------------------------------------------------------------------------------------------

If Param0 Then If Param1 == ".." Then Return ; Leave this script here when called by another script with specified parameter.

;----------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrArrayize3 (strString)
If strString == "" Then Return ArrDimension (0) ; Return a valid empty dim-0 array with no elements.
For intI = 1 To 255
   strDelimiter = Num2Char (intI)
   If !StrScan (strString, strDelimiter, 1, @FWDSCAN)
      objRegExp = ObjectCreate ("VBScript.RegExp")
      objRegExp.IgnoreCase = @FALSE
      objRegExp.Global = @TRUE
      objRegExp.MultiLine = @FALSE
      objRegExp.Pattern = ""
      Return Arrayize (objRegExp.Replace(strString, strDelimiter), strDelimiter)
   EndIf
Next
Return ArrDimension (0) ; Cannot split this string. Return a valid empty dim-0 array with no elements.
;......................................................................................................................
; This UDF udfStrArrayize returns a dim-1 array, whose elements are filled with the successive
; characters of the given input string (one  char = one element).
; The array contains two extra empty elements at index position 0 and Strlen (strString) + 1.
;
; Example: "string" ==> [""|"s"|"t"|"r"|"i"|"n"|"g"|""]
;
; If the given input string is empty or cannot be arrayized, then the UDF returns a dim-0 array with no element.
;
; Detlev Dalitz.20090627.
;......................................................................................................................
#EndFunction
;----------------------------------------------------------------------------------------------------------------------


; Test.

:Test21 ; Empty string.
intBase = 0
strText = ""
arrText = udfStrArrayize2 (strText)
Message ("Test 21", "Array Elements:" : ArrInfo (arrText, 1))
If !ArrInfo (arrText, 0) Then Drop (arrText) ; If array has no dimension, then drop it.


:Test22 ; Create a zero based array.
intBase = 1
strText = "zero based array" ; 16 chars.
arrText = udfStrArrayize2 (strText) ; 16 elements.
Message ("Test 22", "Array Elements:" : ArrInfo (arrText, 1))
If !ArrInfo (arrText, 0)
   Drop (arrText) ; If array has no dimension, then drop it.
Else
   ; Export array to file and have a look into.
   strFileOut = ItemReplace ("txt", -1, FileCreateTemp ("WBT"), ".")
   intBytesWritten = ArrayFilePut (strFileOut, arrText, @TRUE)
   blnResult = RunWait (strFileOut, "")
   blnResult = FileDelete (ItemReplace ("*", -1, strFileOut, "."))
EndIf


:Test23 ; Create a big array.
intBase = 0
strText = "The quick brown fox jumps over the lazy dog."
strText = StrFill (strText, 10000)

Exclusive (@ON)
intTicksStart = GetTickCount ()

arrText = udfStrArrayize2 (strText) ; 10000 elements.

intTicksStop = GetTickCount ()
Exclusive (@OFF)

Message ("Test 23", "Wow, that was fast" : @LF : "Array Elements:" : ArrInfo (arrText, 1) : @LF : "Ticks: " : intTicksStop - intTicksStart)

; Export array to file and have a look into.
strFileOut = ItemReplace ("txt", -1, FileCreateTemp ("WBT"), ".")
intBytesWritten = ArrayFilePut (strFileOut, arrText, @TRUE)
blnResult = RunWait (strFileOut, "")
blnResult = FileDelete (ItemReplace ("*", -1, strFileOut, "."))



:Test31 ; Empty string.
intBase = 0
strText = ""
arrText = udfStrArrayize3 (strText)
Message ("Test 31", "Array Elements:" : ArrInfo (arrText, 1))
If !ArrInfo (arrText, 0) Then Drop (arrText) ; If array has no dimension, then drop it.


:Test32 ; Create a zero based array.
intBase = 1
strText = "zero based array" ; 16 chars.
arrText = udfStrArrayize3 (strText) ; 18 elements.
Message ("Test 32", "Array Elements:" : ArrInfo (arrText, 1))
If !ArrInfo (arrText, 0)
   Drop (arrText) ; If array has no dimension, then drop it.
Else
   ; Export array to file and have a look into.
   strFileOut = ItemReplace ("txt", -1, FileCreateTemp ("WBT"), ".")
   intBytesWritten = ArrayFilePut (strFileOut, arrText, @TRUE)
   blnResult = RunWait (strFileOut, "")
   blnResult = FileDelete (ItemReplace ("*", -1, strFileOut, "."))
EndIf


:Test33 ; Create a big array.
intBase = 0
strText = "The quick brown fox jumps over the lazy dog."
strText = StrFill (strText, 10000)

Exclusive (@ON)
intTicksStart = GetTickCount ()

arrText = udfStrArrayize3 (strText) ; 10002 elements.

intTicksStop = GetTickCount ()
Exclusive (@OFF)

Message ("Test 33", "Wow, that was fast" : @LF : "Array Elements:" : ArrInfo (arrText, 1) : @LF : "Ticks: " : intTicksStop - intTicksStart)

; Export array to file and have a look into.
strFileOut = ItemReplace ("txt", -1, FileCreateTemp ("WBT"), ".")
intBytesWritten = ArrayFilePut (strFileOut, arrText, @TRUE)
blnResult = RunWait (strFileOut, "")
blnResult = FileDelete (ItemReplace ("*", -1, strFileOut, "."))

Exit

;------------------------------------------------------------------------------------------------------------------------------------------
;  Example
;
;  strString = "This is a string." : @CRLF : "Line two."
;
;------------------------------------------------------------------------------------------------------------------------------------------
;  Array
;------------------------------------------------------------------------------------------------------------------------------------------
;    0   T
;    1   h
;    2   i
;    3   s
;    4
;    5   i
;    6   s
;    7
;    8   a
;    9
;   10   s
;   11   t
;   12   r
;   13   i
;   14   n
;   15   g
;   16   .
;   17   @CR
;   18   @LF
;   19   L
;   20   i
;   21   n
;   22   e
;   23
;   24   t
;   25   w
;   26   o
;   27   .
;------------------------------------------------------------------------------------------------------------------------------------------