Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
String parsing
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00273042
Message ID:
00273482
Vues:
38
Hi Joe,

>I have a string I will fget from a file that looks like this...
>"Joe",6.34,"This is a test",11.34
>
>With VB this was very easy to read like this...
>
>Input #1, Name,PayRate,Comment,OTRate
>
>I was going to read in the whole line and
>use a for loop to take data up to the commas.
>Is there an easier way to read or parse this
>with VFP 6.0?

We have this program in our library.
*!******************************************************************************
FUNCTION aparser
	*  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 = aparser(@laWords, lcWordString)
	*  Parameter List....: paWords, pcWordString, pcDelimiter
	********************************************************************
	lparameter paWords, pcWordString, pcDelimiter
	local lnWords, lni
	external array paWords

	if not "FOXTOOLS.FLL" $ set("library")
		set library to foxtools.fll additive
	endif

	pcDelimiter = iif(empty(pcDelimiter), space(1), pcDelimiter)

	lnWords = Words(pcWordString, pcDelimiter)
	
    IF lnWords>0 && Not empty string 
		dimension paWords[lnWords]

		for lni = 1 to lnWords
			paWords[lni] = WordNum(pcWordString, lni, pcDelimiter) && Array of words
		endfor
	ELSE
	    dimension paWords[1] && For empty string lnWords=0
	    paWords[1]=""
	ENDIF    	
	return lnWords
In you case Delimiter will be ','.

HTH
If it's not broken, fix it until it is.


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

Click here to load this message in the networking platform