'===========================================================================
' Subject: SPLIT FUNCTION LIKE VB             Date: 09-16-99 (17:37)       
'  Author: Dave Navarro, Jr.                  Code: PBCC, PBDLL            
'  Origin: dave@powerbasic.com              Packet: PBCC.ABC
'===========================================================================
'
' Perform the same operation as the SPLIT function in Visual Basic 6.0
'
' Takes a string and splits it into a string array based on a specified
' delimeter.  If you don't specify a delimeter, a space is assumed.
'
' Split will work in PB/DLL or PB/CC.
'

SUB Split(BYVAL expression AS STRING, BYVAL delimeter AS STRING, StrArray() AS STRING)

  LOCAL c AS LONG
  LOCAL x AS LONG

  IF LEN(delimeter) = 0 THEN
    delimeter = " "
  END IF

  c = MAX(PARSECOUNT(expression, delimeter), 1)

  REDIM StrArray(0 to c - 1) AS STRING

  FOR x = 1 TO c
    StrArray(x - 1) = PARSE$(expression, delimeter, x)
  NEXT

END SUB

FUNCTION PbMain()

  LOCAL x AS LONG

  DIM s(0 to 0) AS STRING

  Split "This is what it's all about", "", s()

  FOR x = 0 TO UBOUND(s())
    PRINT s(x)
  NEXT

END FUNCTION
