Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extract numbers from string
Message
From
06/01/2003 13:30:37
 
 
To
06/01/2003 13:29:37
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00738451
Message ID:
00738453
Views:
15
>i have one string
>
>lcString = "18,21,33,45,150,999"
>
>I want extract numbers
>
>18
>21
>33
>45
>150
>999
>
>"," is separator between numbers

See the following two functions:
* Return the number of parameters in a list
* expC1 Parameter list
* expC2 Delimiter (default is the comma)
FUNCTION ParmCnt
PARAMETER tcParms,tcDelimiter
LOCAL lcDelimiter
IF TYPE('tcDelimiter')<>'C'
   lcDelimiter=','
   ELSE
   lcDelimiter=tcDelimiter
ENDIF
RETURN IIF(EMPTY(tcParms),0,OCCURS(lcDelimiter,tcParms)+1)


* Return a parameter value from a list
* expC1 Parameter list
* expN1 Parameter number
* expC2 Delimiter (default is the comma)
FUNCTION GetParm
PARAMETERS tcParms,tnNo,tcDelimiter
LOCAL lcDelimiter,lnBPos,lnEPos
IF TYPE('tcDelimiter')<>'C'
   lcDelimiter=','
   ELSE
   lcDelimiter=tcDelimiter
ENDIF
lnBPos=AT(lcDelimiter,lcDelimiter+tcParms+lcDelimiter,tnNo)
lnEPos=AT(lcDelimiter,lcDelimiter+tcParms+lcDelimiter,tnNo+1)
RETURN SUBSTR(tcParms,lnBPos,lnEPos-lnBPos-1)
Call ParmCnt() to get the number of items, then just loop with FOR NEXT to get each of them by the use of GetParm().
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Reply
Map
View

Click here to load this message in the networking platform