Welcome! Log In Create A New Profile

Advanced

How to pull apart an address string

Posted by Joel 
Joel
How to pull apart an address string
June 15, 2009 09:17PM
Hi!

In a WebDev project, I have imported a dbase with an address string that looks like this:

186 Center Street
Manchester, CT 06040

There appears to be some sort of a CR after the street address as it always populates 2 lines.

I need to pull that address apart to drop the pieces into separate fields -
Address (with no CR)
City
State
Zip (most are the 6 digit variety, but not all)

Does anyone have a bit of code that ca reliably do this?
Fabrice Harari
Re: How to pull apart an address string
June 15, 2009 10:46PM
Hi Joel

it depends of several things (and that's why software extracting addresses automatically, like quickbook, often are making a poor job out of it)

By example:
- Is the zipcode always at the end?
- Is the zipcode always there?
- Is there always a state?
- is there always a "," after the city?
- are there always ONLY 2 lines in the address?

If the answer is YES to all these questions then the code would be something like that (not tested so bugs are probable)
sAddress is string
sLine2 is string
sAddress=extractring(Orig,1,CR)
sLine2=extractstring(Orig,2,CR)
sCity is string=Extractstring(sLine2,1,",")
sZip is string=Extractstring(sLine2,1," ",FromEnd)
sState is string=Extractstring(sLine2,2," ",FromEnd)

If the answer is no to any of the questions above then you must have code testing the actual formatting of the address to decide in what case you are (with or without zip code by example), and then use the coding appropriate in each case.

Best regards

Author:

Your Email:


Subject:


Spam prevention:
Please, enter the code that you see below in the input field. This is for blocking bots that try to post this form automatically. If the code is hard to read, then just try to guess it right. If you enter the wrong code, a new image is created and you get another chance to enter it right.
Message: