Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
String to Array
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00470612
Message ID:
00470632
Vues:
35
>>>I have a string similar to "text1,text2,text3,etc...". I want to be able to break out each item and store to an array (i.e. STORE "text1" to lArray(i)).
>>>What is the fastest and easiest way to do this?
>>>
>>>Thanks in advance for your help,
>>Russell,
>>
>>You can of course use OCCURS(",", lcstring) + 1, then AT() to determine the position etc. I'm sure someone will recommend that. I will, however, recommend the following:
* Assumes Foxtools is one the search path
>>SET LIBRARY TO FOXTOOLS ADDITIVE
>>lcstring = "text1,text2,text3"
>>lnwords = Words(lcstring, ",")
>>DIMENSION myarray[lnwords]
>>FOR lni = 1 TO lnwords
>>  myarray[lni] = WordNum(lcstring, lni, ",")
>>NEXT
>
>Hi George,
>
>Long time ago (about two years) there was a similar thread and I proposed this solution. Cetin explained me, that it would be slow for big strings and sent me his fll for doing that.
>
Correction: (make it back to use strtran instead of chrtran, because there could be several delimiters, like **).


>Another idea, which was in the same thread:
>
>*!******************************************************************************
>function aparser1
>*  Description.......: Function parses a text string into an array.
>*                    : Each element of the array contains one word...
>*  Calling Samples...: dimension laWords[1]
>*                    : lcWordString = "Some text string"
>*                    : lnWords = aparser1(@laWords, lcWordString)
>*  Parameter List....: taWords, tcWordString, tcDelimiter
>********************************************************************
>lparameter taWords, tcWordString, tcDelimiter
>local lnWords, lni
>external array taWords
>
>if vartype(tcDelimiter)'C'
>     tcDelimiter=space(1) && Default delimiter
>endif
>*!* Replace the delimiter with CHR(13) using STRTRAN.
>tcWordString = strtran(tcWordString, tcDelimiter, chr(13))
>*!* Now put each element in an array.
>lnWords=alines(taWords, tcWordString)
>return lnWords
>
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform