udfStrArrayize (1)
arr udfStrArrayize (str, int)
;----------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrArrayize (strString, intBase)
If strString == "" Then Return ArrDimension (0) ; Return a 0-dim array with no element, must be checked by the caller.
intStrLen = StrLen (strString)
Switch !!intBase
Case 0
   arrArray = ArrDimension (intStrLen)
   For intElem = 1 To intStrLen
      arrArray [intElem - 1] = StrSub (strString, intElem, 1)
   Next
   Break
Case 1
   arrArray = ArrDimension (intStrLen + 1)
   arrArray[0] = intStrLen
   For intElem = 1 To intStrLen
      arrArray [intElem] = StrSub (strString, intElem, 1)
   Next
   Break
EndSwitch
Return arrArray
;----------------------------------------------------------------------------------------------------------------------
; This UDF "udfStrArrayize" splits the given string into separate characters
; and returns a 1-dim array which contains one character per field element.
;
; If input string is empty, then this UDF returns a pseudo 'empty' 1-dim array.
; The caller has to check this error result using function 'ArrInfo (array, 1)'.
;
; 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.20020516.20090507.
;----------------------------------------------------------------------------------------------------------------------
#EndFunction
;----------------------------------------------------------------------------------------------------------------------


; Test.

:Test1
strString = ""
intBase = 0 ; Zero based array.
arrArray = udfStrArrayize (strString, intBase)
GoSub DisplayMessage

:Test2
strString = "that's a string"
intBase = 0 ; Zero based array.
arrArray = udfStrArrayize (strString, intBase)
GoSub DisplayMessage

:Test3
strString = "that's a string"
intBase = 1 ; One based array.
arrArray = udfStrArrayize (strString, intBase)
GoSub DisplayMessage

Exit

;------------------------------------------------------------------------------------------------------------------------------------------
:DisplayMessage

strMsgTitle = "Demo: udfStrArrayize (strString, intBase)"
strMsgText  = StrCat ('strString = "', strString, '"', @LF, 'arrArray  =', @LF)

If 1 == ArrInfo (arrArray, 0) ; Is it a dim-1 array?
   intCount = ArrInfo (arrArray, 1) - 1
   For intElem = 0 To intCount
      strMsgText = StrCat (strMsgText, '[', intElem, ']', @TAB, arrArray [intElem], @LF)
   Next
   Message (strMsgTitle, strMsgText)
Else
   strMsgText = StrCat (strMsgText, 'Array dimension does not fit.', @LF)
   strMsgText = StrCat (strMsgText, 'Maybe: String is empty, cannot create Array.', @LF)
   Message (strMsgTitle, strMsgText)
EndIf

Return ; from GoSub DisplayMessage.
;------------------------------------------------------------------------------------------------------------------------------------------