| Author | Topic: Convert comma delimited string into array |
---|
| Nestor G. Torres | Convert comma delimited string into array
on Thu, 12 Dec 2013 16:59:16 +0200Hi 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. Torres | Re: Convert comma delimited string into array
on Thu, 12 Dec 2013 18:18:14 +0200On 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 Borzic | Re: Convert comma delimited string into array
on Fri, 13 Dec 2013 04:46:48 +0100Nestor 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. Torres | Re: Convert comma delimited string into array
on Fri, 27 Dec 2013 20:48:24 +0200On 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 Brandel | Re: Convert comma delimited string into array
on Sat, 01 Feb 2014 20:22:03 +0100It should work easier:
cTxt := "89 , 32, 34"
aTxt := &("{ "+cTxt+" }")
cTxt := " 'one','two','three'"
aTxt := &("{ "+cTxt+" }")
this code is not tested, but it should work. |