Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Matching parts of two Strings
Message
From
17/09/2002 03:09:29
 
 
To
17/09/2002 01:49:26
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00700976
Message ID:
00701116
Views:
17
>yourstring="123,456,abc"
>STREXTRACT( yourstring, ",", "", 3)
>
>>will extract "abc", the last field, in the above example
>Sorry, I left out the occurance number, "3". Using my eye as a compiler has it's limits.

Yes, I sensed a typo somewhere in your message.

> Yes, you could say this is special case handling for the first and last fields. In the case of the last field you have to know how many fields there are.

>>>With the array approach we don't have to know in advance how many elements are in the strings and we can loop through them without having to worry about that (with ALEN() function or FOR EACH construct). And one can even easily check if both strings have the same number of elements (don't know if this should add to the original problem's requisits).

I suppose if you wanted a generalized approach you could do something like the following. I don't know if it's worth the effort but at least it returns all the fields in the string.
yourstring="123,456,789,ABC"
FOR i = 1 TO OCCURS(",",yourstring) + 1
    lcField  = "field" + LTRIM(STR(i))
    &lcField = STREXTRACT(","+yourstring+",", ",", ",",  i )
    ?"&lcfield.=" + &lcField
ENDFOR
Scott Ramey
BDS Software
Previous
Reply
Map
View

Click here to load this message in the networking platform