Alaska Software Inc. - Convert comma delimited string into array
Username: Password:
AuthorTopic: Convert comma delimited string into array
Nestor G. TorresConvert comma delimited string into array
on Thu, 12 Dec 2013 16:59:16 +0200
Hi Guys,

I've been looking hi and low for a function that converts a comma 
delimited string into an array.

Is there such a function in Alaska xbase or the topdown libraries or 
anywhere else i can use.

Kind regards
Nestor
Nestor G. TorresRe: Convert comma delimited string into array
on Thu, 12 Dec 2013 18:18:14 +0200
On 2013/12/12 04:59 PM, Nestor G. Torres wrote:
> Hi Guys,
>
> I've been looking hi and low for a function that converts a comma
> delimited string into an array.
>
> Is there such a function in Alaska xbase or the topdown libraries or
> anywhere else i can use.
>
> Kind regards
> Nestor

I 've gotten over being lazy about this and wrote my own to fit my purpose:

//************************************************
Function Customer_Order_Array(cOrder )
//************************************************
Local aOrder:={}, nStart:=1, nPos:=0, nLen:=0, cStkno:=""
Local cName:="", nQuantity:=0, nPrice:=0
nPos:=At(",", cOrder, nStart)
nlen:=len(cOrder)
Do while nPos!=0
   cStkno:=Substr(cOrder,nStart,nPos-nStart)
   nStart:=nPos+1

   nPos:=At(",", cOrder, nStart)
   cName:=Substr(cOrder,nStart,nPos-nStart)
   nStart:=nPos+1


   nPos:=At(",", cOrder, nStart)
   nquantity:=Val( Substr(cOrder,nStart,nPos-nStart))
   nStart:=nPos+1


   nPos:=At(",", cOrder, nStart)
   If nPos != 0
     nprice:=Val( Substr(cOrder,nStart,nPos-nStart))
     nStart:=nPos+1
   Else
     nprice:=Val( Substr(cOrder,nStart,nPos-(nlen+1)))
   Endif


   AAdd(aOrder, {cStkno,cName, nQuantity, nPrice})
Enddo

Return aOrder
Boris BorzicRe: Convert comma delimited string into array
on Fri, 13 Dec 2013 04:46:48 +0100
Nestor G. Torres wrote in news:428603ae$5661175b$12aed@news.alaska-
software.com:

> I've been looking hi and low for a function that converts a comma 
> delimited string into an array.

Here is what I use:

FUNCTION String2Array( cString, cDelim )
   Local i, aData[0], nLen := Len(cDelim), nPos := 1

   while (i := at(cDelim, cString, nPos)) > 0
      AAdd( aData, SubStr(cString, nPos, i-nPos) )
      nPos := i+nLen
   end

   if nPos-nLen <= Len(cString)
      AAdd( aData, SubStr(cString, nPos) )
   endif
   Return aData


Best regards,
Boris Borzic

http://xb2.net
http://sqlexpress.net
industrial strength Xbase++ development tools
Nestor G. TorresRe: Convert comma delimited string into array
on Fri, 27 Dec 2013 20:48:24 +0200
On 2013/12/13 05:46 AM, Boris Borzic wrote:
> Nestor G. Torres wrote in news:428603ae$5661175b$12aed@news.alaska-
> software.com:
>
>> I've been looking hi and low for a function that converts a comma
>> delimited string into an array.
>
> Here is what I use:
>
> FUNCTION String2Array( cString, cDelim )
>     Local i, aData[0], nLen := Len(cDelim), nPos := 1
>
>     while (i := at(cDelim, cString, nPos)) > 0
>        AAdd( aData, SubStr(cString, nPos, i-nPos) )
>        nPos := i+nLen
>     end
>
>     if nPos-nLen <= Len(cString)
>        AAdd( aData, SubStr(cString, nPos) )
>     endif
>     Return aData
>
>
Hi Boris

Thanks for the reply.

And Merry Christmas and may you have a great new year.

Kind regards,
Nestor
Hubert BrandelRe: Convert comma delimited string into array
on Sat, 01 Feb 2014 20:22:03 +0100
It should work easier:

cTxt := "89 , 32, 34"
aTxt := &("{ "+cTxt+" }")

cTxt := " 'one','two','three'"
aTxt := &("{ "+cTxt+" }")

this code is not tested, but it should work.