Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Extracting a Portion of a String
Message
From
21/12/2007 20:10:08
Jay Johengen
Altamahaw-Ossipee, North Carolina, United States
 
 
To
21/12/2007 19:52:21
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01277122
Message ID:
01277128
Views:
23
>>I need to extract the 21 and 22 from this string to get "2122"
>>
>>
>>23^^C4~21^^C4~22^^C4
>>
>>
>>Or it could look like this:
>>
>>
>>23^^C4~22^^C4
>>
>>
>>And I would only want "22"
>
>For these two,
>
>lcChop=strextract(lcString, "~", "^^", i)
>
>(i =1,2, 3,...)
>
>>Or this:
>>
>>
>>23^^C4~21^^C4~22^^C4~27^^C4
>>
>>
>>In which case I want "212227"
>>
>>The only truly consistent thing is that there will always be a tilde before the numbers I want.
>
>If the ending delimiter isn't sure to be a ^^, you can go like this:
>
>lcDig=""
>for i=1 to getwordcount(lcS, "~")
>   lcWord=getwordnum(lcS, i, "~")
>   j=1
>   do while isdig(substr(lcWord,j))
>      lcdig=lcdig+substr(lcWord,j,1))
>   enddo
>endfor
>outer loop counts words split at tilde, inner pulls starting digits from these words until a non-digit is encountered..

I did it like this:
CLEAR 

m.ModString = "23^^C4~21^^C4~22^^C4~27^^C4"

m.ModCount = OCCURS('~', m.ModString)

m.Mods = ''

FOR ModLoop = 1 TO m.ModCount
	m.Mods = m.Mods + SUBSTR(m.ModString, AT('~', m.ModString, ModLoop) +1, 2)
ENDFOR

? m.Mods
But I think yours is cleaner.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform