Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert a delimited string to an array
Message
From
01/09/1999 07:48:08
Kenneth Downs
Secure Data Software, Inc.
New York, United States
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00259451
Message ID:
00260057
Views:
18
Scott,

Below is some simple code I've been using forever. You can add a couple of doo-dads to correct for leading commas or to use another delimiter. Hope this helps. Note that the array must be passed by reference.
PROCEDURE sysArrayFromComma
LPARAM ArrayName,CommaList
LOCAL ln1

IF RIGHT(CommaList,1) <> ","
  CommaList = CommaList + ","
ENDIF

ln1 = 0
DO WHILE LEN(CommaList) > 1
  ln1 = ln1 + 1
  IF ln1 > 1
    DECLARE ArrayName(ln1)
  ENDIF

  ArrayName(ln1) = LEFT(CommaList, AT(",", CommaList)-1)
  
  IF AT(",",CommaList) = LEN(CommaList)
    CommaList = ""
  ELSE
    CommaList = SUBS(CommaList,AT(",",CommaList)+1)
  ENDIF
ENDDO

RETURN ln1
>The title says it all. Suppose you have any of the following strings:
>
>123 12 456
>123456
>123, 32,99
> 999, 88 777777,
>,123,
>
>You and I can see through the delimiters and user input anomalies, but I'd like to have a function to pick out the data and ignore the delimiters, and put the data into an array.
>
>Thanks and Aloha!
>Scott
Previous
Reply
Map
View

Click here to load this message in the networking platform