PBDR.COM

About   -   Contact   -   Purchase   -   Search   -   What's New

 
 
Quick String to Array Function

Mike Bartos has spent some time optimizing this routine to convert a string into an unbound array.

/**************************************************************
Powerbuilder 6.5 / 7.0

long StringToArray( readonly string sString,
               readonly string sSeparator,
               reference string sOutputArray[] )

This function parses string to array depending on the
string separator. The count of items parsed is returned.

          by Mike Bartos (yawor@yawor.com)

****************************************************************/
LONG lPosEnd, lPosStart = 1, lSeparatorLen, lCounter = 1

IF UpperBound(sOutputArray) > 0 THEN sOutputArray = {""}
lSeparatorLen = len(sSeparator)

lPosEnd = Pos (sString, sSeparator, 1)

DO WHILE lPosEnd > 0
     sOutputArray[lCounter] = Mid (sString, lPosStart, lPosEnd - lPosStart)
     lPosStart = lPosEnd + lSeparatorLen
     lPosEnd = Pos (sString, sSeparator, lPosStart)
     lCounter++
LOOP

sOutputArray[lCounter] = Right (sString, Len(sString) - lPosStart + 1)
RETURN lCounter
 

Top of Page

Legal Notice

Ken Howe 2011