Get street name and Apt number from address

Thank you for stopping by my post, it’s good that I scratched my head for a long time, the requirement, which sounded quite simple, turned out to be difficult, below the requirement ....

I need to write off (street number, street name, Suite \ Apt information or any zip code found)

The address is as follows:

  • 123 Main St
  • 123 NW.17 St
  • One Washington Way Suite 405
  • 1 Government No. 400, Washington, 01211

So far I have managed to allocate 123 Main St, but whenever I go further, using the Char \ Pat index in my line, the address from the line above 2 gets scrambling, for example, it becomes (123 NW St)

My main goal is to break the htis row and put it in the table and then concatenate .....

Any help would be greatly appreciated.

+4
source share
2 answers

Parsing addresses is a nightmare in my experience. There are probably at least a dozen ways to present the same address, and it will be difficult for you to find a reliable way to stretch the pieces.

My recommendation would be to pass any address that you have to the mapping service (google, yahoo whatever) and use the results that they pass to you. Smarter people than you and I have found a very reliable way to do this. I would recommend taking advantage of what they offer.

+8
source

Well, this is my alternative suggestion, not the answer to your question.

The string manipulation operation is always very important and tedious, and for a long time it does not work perfectly.

I have a very good alternative that you would prefer. Instead of having one line address, it is better to split into another part.

eg. Street1 street # 2 city state country

Now in the database you can create an XML data type and save all the above field in a field in XML format, for example

<Address> <street1>data1</street1> <street2>data2</street2> <city>data3</city> <state>data4</state> <country>data5</country> </Address> 

The advantage of this:

1. Now you can flexibly insert and retrieve data, if the user does not want to enter any field, or you do not want to display any field, then this is the best way to do it.
2.It will give you good performance, but because XML Parsing is faster than string manipulation.
3.XML returns more precision than a string operation.

-2
source

All Articles