udfStrAnsiToArray
arr udfStrAnsiToArray (str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrAnsiToArray (strTextAnsi, intBase)
If strTextAnsi == "" Then Return ArrDimension (0)
strDelim = Num2Char (1) ; Surrogate char.
intSizeBB = StrLen (strTextAnsi) << 1
hdlBB = BinaryAlloc (intSizeBB)
BinaryPokeStrW (hdlBB, 0, strTextAnsi)
BinaryReplace (hdlBB, "", strDelim, @TRUE)
If !intBase
   arrText = Arrayize (BinaryPeekStr (hdlBB, 0, intSizeBB - 1), strDelim)
Else
   arrText = Arrayize (intSizeBB >> 1 : strDelim : BinaryPeekStr (hdlBB, 0, intSizeBB - 1), strDelim)
EndIf
hdlBB = BinaryFree (hdlBB)
Return arrText
;......................................................................................................................
; This UDF udfStrAnsiToArray returns a dim-1 array, whose elements are filled with the successive
; characters of the given input ansi string (one ansi char = one Byte = one element).
;
; If the given input string is empty, then the UDF returns a dim-0 array with no element.
;
; intBase = 0 ... Create zero-based array.
;                 String length resp. array dimension can be evaluated by WinBatch function "ArrInfo (array, 1)".
; intBase = 1 ... Create one-based array.
;                 Array element [0] contains the length of the string as an integer number.
;
; Detlev Dalitz.20090410.20090507.
;......................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

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


:Test2 ; Create a one based array.
intBase = 1
strText = "one based array" ; 15 chars.
arrText = udfStrAnsiToArray (strText, intBase)
Message ("Test 1", "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


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

Exclusive (@ON)
intTicksStart = GetTickCount ()

arrText = udfStrAnsiToArray (strBigText, intBase)

intTicksStop = GetTickCount ()
Exclusive (@OFF)

Message ("Test 3", "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

; This is a step by step variant of the above udf.
;   ;----------------------------------------------------------------------------------------------------------------------
;   #DefineFunction udfStrAnsiToArray (strTextAnsi)
;   strDelim = Num2Char (7) ; Surrogate char.
;   hdlBB = BinaryAlloc (2 * StrLen (strTextAnsi))
;   intBytes = BinaryPokeStrW (hdlBB, 0, strTextAnsi)
;   intBytes = BinaryReplace (hdlBB, "", strDelim, @TRUE)
;   strTemp = BinaryPeekStr (hdlBB, 0, BinaryEODGet (hdlBB) - 1)
;   hdlBB = BinaryFree (hdlBB)
;   arrText = Arrayize (strTemp, strDelim)
;   Return arrText
;   #EndFunction
;   ;----------------------------------------------------------------------------------------------------------------------