Parse To Array

This parses a text string to an array, based on the delimiter passed.

ParseToArray calls ParseToArray which can be found on the previous page.
Here's some example code:
Array Text(aParsedText;0)
$Text:="Bob,Ted,Carol,Alice"
$ElementCount:=ParseToArray($Text;->aParsedText;",")

  ` ParseToArray
  ` Parses text passed to a text array as per the delimiter passed
  ` $1 - Text
  ` $2 - Array Pointer
  ` $3 - Delimiter
  ` $4 - Max length for any element
  ` $0 - Size of array returned

C_TEXT($Text;$1;$DelimitStr;$3;$FieldText)
C_POINTER($ArrayPtr;$2)
C_LONGINT($0;$Len;$Pos;$Ndx;$LastPos;$DelimitCount;$BreakWidth;$TextLength;$TextLength2)

$Text:=$1
$ArrayPtr:=$2
$DelimitStr:=$3
If (Count parameters>=4)
  $BreakWidth:=$4
Else 
  $BreakWidth:=MAXTEXTLEN 
End if 

$TextLength:=Length($Text)
$TextLength2:=Length(Replace string($Text;$DelimitStr;""))
$DelimitCount:=($TextLength-$TextLength2)/Length($DelimitStr)
$DelimitLength:=Length($DelimitStr)

ArrayResize ($DelimitCount*2+1;$ArrayPtr)  ` *2 is for padding

$LastPos:=0
$Ndx:=0
While (Length($Text)>0)
  $Pos:=Position($DelimitStr;$Text)
  If ($Pos<=0)
    $Pos:=Length($Text)+$DelimitLength  `1
  End if 
  $Len:=$Pos-1
  If ($Len>$BreakWidth)
    $Len:=$BreakWidth
    $Pos:=$Len  ` This is to keep the character that's at the "new" position.
  End if 
  
  $FieldText:=Substring($Text;1;$Len)
  If ($Pos0)
    `$FieldText:=Substring($FieldText;1;$BreakWidth)
    `End if 
  $ArrayPtr->{$Ndx}:=$FieldText
End while 

If (Size of array($ArrayPtr->)>$Ndx)
  DELETE ELEMENT($ArrayPtr->;$Ndx+1;Size of array($ArrayPtr->))
End if 

$0:=Size of array($ArrayPtr->)