Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Parsing a Street Address into Separate Fields
Message
De
14/08/2006 09:21:33
 
 
À
12/08/2006 15:53:32
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01144790
Message ID:
01145281
Vues:
30
Hi John,

I just sent you an email with examples and my notes from testing...

:o)


>Here it is:
>
>I have to admit, I felt sordid writing this. First I had to CREATE tracy, then USE tracy, and most ashamedly DO tracy :-)
>
>
>
>** Requires tracy.dbf with same structure you mentioned, plus a field to hold addreess string C(100)
>
>USE tracy
>SCAN
>	cAddress=tracy.address
>	
>	cNumber=GETWORDNUM(cAddress,1)
>	
>	cSt_Prefix=""  && Might not be one
>	FOR i = 2 TO GETWORDCOUNT(cAddress)
>		IF LEN(GETWORDNUM(cAddress,i)) <= 2    && Must be a street prefix
>			cSt_Prefix=cSt_Prefix+" "+GETWORDNUM(cAddress,i)
>		ELSE
>			EXIT  && No More
>		ENDIF
>	ENDFOR
>	cStreet = GETWORDNUM(cAddress,i)  && After prefix(es), has to be street name
>	IF LEN(GETWORDNUM(cAddress,i+1)) >= 5 AND UPPER(GETWORDNUM(cAddress,i+1)) # "SUITE"
>		cStreet=cStreet+" "+GETWORDNUM(cAddress,i+1)
>		i=i+1
>	ENDIF
>	cSt_type = GETWORDNUM(cAddress,i+1)  && After street, has to be type
>	cTestLast=GETWORDNUM(cAddress,GETWORDCOUNT(cAddress))
>	lIsApt=.F.
>	cApt_Room = ""  && Might not be one
>	FOR j = 1 TO LEN(cTestLast)
>		IF VAL(SUBSTR(cTestLast,j,1)) > 0 OR LEN(cTestLast) = 1 && Probably an Apt/Ste
>			lIsApt=.T.
>			EXIT
>		ENDIF
>	ENDFOR
>	IF lIsApt
>		cApt_Room = cTestLast
>	ENDIF
>	cSt_Suffix = ""
>	FOR k = GETWORDCOUNT(cAddress) TO i+2 STEP -1
>		IF LEN(GETWORDNUM(cAddress,K)) <= 2 AND ;
>				GETWORDNUM(cAddress,k) # cApt_Room
>			cSt_Suffix=cSt_Suffix+" "+GETWORDNUM(cAddress,k)
>		ENDIF
>	ENDFOR
>
>	cSt_Prefix=CleanIt(cSt_Prefix)
>	cSt_Suffix=CleanIt(cSt_Suffix)
>	
>	REPLACE ;
>		number WITH cNumber, ;
>		st_prefix WITH cSt_prefix, ;
>		street WITH cStreet, ;
>		st_type WITH cSt_Type, ;
>		st_Suffix WITH cSt_Suffix, ;
>		apt_Room WITH cApt_Room
>ENDSCAN
>	
>		
>PROCEDURE CleanIt(cString)	
>cFixed=""
>FOR num = 1 TO GETWORDCOUNT(cString)
>	cFixed=cFixed+UPPER(LEFT(GETWORDNUM(cString,num),1))
>ENDFOR
>RETURN cFixed
>
>
>
>>This must've been done a thousand times already. I have parsed addresses before but I cannot seem to wrap my head around this today. (Friday)
>>
>>Some examples of user typed values:
>>
>>100 N Main St
>>3001 No W Rubick Ave     && number=3001, st_prefix = No, Street=W Rubick, st_type = Ave
>>12 Sycamore Dairy Rd NW  && number = 12, street=Sycamore Dairy, st_type=Rd, st_suffix = NW
>>1312 S Cain St E Suite A10 && number = 1313, st_prefix=S, street=Cain, st_type=St, st_suffix=E, apt_room=Suite A10
>>100 N Main St NW Ste 110
>>210 Jones Dr Apt 1E
>>8700 Smith Rd
>>
>>Parse the values typed above into these fields:
>>
>>number c(10)        && 100, 3001, 12, 1312, 100, 210, ...
>>st_prefix c(10)     && NW, S, E, NE...
>>street c(30)        && Main, Cain, ...
>>st_type c(10)       && Blvd, ST, AV, ...
>>st_suffix c(10)     && NW, S, E, NE, ...
>>apt_room c(10)      && Apt 102, Suite 109, etc...
>>
>>
>>Anyone up to the task on a Friday?
>>
>>TIA,
>>Tracy
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform