Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parsing Data
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Divers
Thread ID:
00667640
Message ID:
00667709
Vues:
23
>I have a table that has been given to me to strip data into seperate fields
>The table has one field that contains city,state and zip in one field and I need to seperate them into seperate fields. Normally I sue case statements an search for blank between the data, but ths has become tedious and ineffective. The reason being mostly is that the data normally looks something like this: 'Upper Saddle River NJ 07458' with many trailing spaces to the right of the string. I tried RTRIM function Replace all citystatezip with RTRIM(CITYSTATEZIP) but that did not eliminate the trailing spaces.
>
>Is there an easier way to parse out this data???

Try this. You will need to modify it to fit your needs.
*/* Program to parse out an address from a field to city, state, zip.

clos data all
LOCAL doIt, nCount
USE "YourTable"
nCount = 0

SCAN
doIt=0
		for i = 1 to 50 &&the length of YourField or the length of the longest entry
			if substr("YourField",i,1)==","
				cityTemp=substr(YourField,1,i-1)
				if (substr(YourField,i+3,1)==" " ;
				  or (substr(YourField,i+4,1)==" " ;
					stateTemp=substr(YourField,i+1,3)
					zipTemp=alltrim(substr(YourField,i+5,len(YourField)))
					replace city with alltrim(cityTemp)
					replace state with alltrim(statetemp)
					replace zip with alltrim(ziptemp)
					exit

				else
					doIt=i
				endif
			endif
		endfor
		if doIt<>0
			stateZip(alltrim(substr(citysold,doIt+1,len(citysold))))
			doIt=0
		endif
**********************************
procedure stateZip(szVal)
	split=0
	for j = 0 to len(szVal)-1
		if substr(szVal,len(szVal)-j,1)==" "
			split=j
			exit
		endif
	endfor

	replace city with alltrim(cityTemp)
	replace state with alltrim(substr(szVal,1,len(szVal)-split))
	replace zip with alltrim(substr(szVal,len(szVal)-split,len(szVal)))
endproc
Winn Pauley
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform