Question

i am using gmail contacts api but the address is all in one string. is there any standard parser to parse a single string into a proper address object with the following fields:

Street Address 1
Street Address 2
City
State
Zip

Was it helpful?

Solution

This SO thread addresses the same issue for Java -- but the selected answer is language agnostic, it just shows how to form a URL from the unstructured address and send it for parsing to Google Maps (with its wealth of information about city names, street names, etc).

This other SO thread has much more discussion and proposes many solutions, including one providing complete, stand-alone Visual Basic code.

Do you need help translating the VB (or other solutions) to C#?

OTHER TIPS

If you are getting this data from the google contact and you happen to be tapping into <gd.postalAddress> Take look at <gd:structuredPostalAddress> instead, where you won't have to parse since it will have the elements broken out for you already.

Though there were some bugs in it earlier this year, they may be worked out by now

There is not a standard parser for addresses; You might look at the suggestions in this question: Parse usable Street Address, City, State, Zip from a string but it seems US centric. There's also the recommendation of using the google maps API. This is actually very useful, but it's rate limited.

I suspect it depends very much on the class you are using and the configuration you use to call the api. Perhaps you could post an example of the string you receive. is it not xml or json already?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top