473,498 Members | 98 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does anyone know how to parse an address from a text field?

62 New Member
I want to parse an address from a text field.
for example
Expand|Select|Wrap|Line Numbers
  1. textbox data = 123 test street, mountain view, CA 91302
  2.  
  3. Dim address = Address.text
  4.  
  5. parse(address)
to
Address1
Address2
City
State
Zip


I found someones sample code, but it doesn't work all that well.

here it is non the less

Expand|Select|Wrap|Line Numbers
  1.  
  2.  Public Function parseAddress(ByVal input As String) As Collection
  3.         input = input.Replace(",", "")
  4.         input = input.Replace("  ", " ")
  5.         Dim splitString() As String = Split(input)
  6.         Dim streetMarker() As String = New String() {"street", "st", "st.", "avenue", "ave", "ave.", "blvd", "blvd.", "highway", "hwy", "hwy.", "box", "road", "rd", "rd.", "lane", "ln", "ln.", "circle", "circ", "circ.", "court", "ct", "ct."}
  7.         Dim address1 As String
  8.         Dim address2 As String = ""
  9.         Dim city As String
  10.         Dim state As String
  11.         Dim zip As String
  12.         Dim streetMarkerIndex As Integer
  13.  
  14.         zip = splitString(splitString.Length - 1).ToString()
  15.         state = splitString(splitString.Length - 2).ToString()
  16.         streetMarkerIndex = getLastIndexOf(splitString, streetMarker) + 1
  17.         Dim sb As New StringBuilder
  18.  
  19.         For counter As Integer = streetMarkerIndex To splitString.Length - 3
  20.             sb.Append(splitString(counter) + " ")
  21.         Next counter
  22.         city = RTrim(sb.ToString())
  23.         Dim addressIndex As Integer = 0
  24.  
  25.         For counter As Integer = 0 To streetMarkerIndex
  26.             If IsNumeric(splitString(counter)) _
  27.             Or splitString(counter).ToString.ToLower = "po" _
  28.             Or splitString(counter).ToString().ToLower().Replace(".", "") = "po" Then
  29.                 addressIndex = counter
  30.                 Exit For
  31.             End If
  32.         Next counter
  33.  
  34.         sb = New StringBuilder
  35.         For counter As Integer = addressIndex To streetMarkerIndex - 1
  36.             sb.Append(splitString(counter) + " ")
  37.         Next counter
  38.  
  39.         address1 = RTrim(sb.ToString())
  40.  
  41.         sb = New StringBuilder
  42.  
  43.         If addressIndex = 0 Then
  44.             If splitString(splitString.Length - 2).ToString() <> splitString(streetMarkerIndex + 1) Then
  45.                 For counter As Integer = streetMarkerIndex To splitString.Length - 2
  46.                     sb.Append(splitString(counter) + " ")
  47.                 Next counter
  48.             End If
  49.         Else
  50.             For counter As Integer = 0 To addressIndex - 1
  51.                 sb.Append(splitString(counter) + " ")
  52.             Next counter
  53.         End If
  54.         address2 = RTrim(sb.ToString())
  55.  
  56.         Dim output As New Collection
  57.         output.Add(address1, "Address1")
  58.         output.Add(address2, "Address2")
  59.         output.Add(city, "City")
  60.         output.Add(state, "State")
  61.         output.Add(zip, "Zip")
  62.         Return output
  63.     End Function
  64.  
  65.     Private Function getLastIndexOf(ByVal sArray As String(), ByVal checkArray As String()) As Integer
  66.         Dim sourceIndex As Integer = 0
  67.         Dim outputIndex As Integer = 0
  68.         For Each item As String In checkArray
  69.             For Each source As String In sArray
  70.                 If source.ToLower = item.ToLower Then
  71.                     outputIndex = sourceIndex
  72.                     If item.ToLower = "box" Then
  73.                         outputIndex = outputIndex + 1
  74.                     End If
  75.                 End If
  76.                 sourceIndex = sourceIndex + 1
  77.             Next
  78.             sourceIndex = 0
  79.         Next
  80.         Return outputIndex
  81.     End Function
  82.  
  83.  
  84.  

any help would be greatly appreciated
Nov 7 '10 #1
1 2250
vertigo262
62 New Member
anyone? :)
Nov 18 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
5211
by: steve deno | last post by:
In 6i, if there was an LOV on an item and the user entered the field, a box with 3 dots popped up. It seems this does not happen in 9i. Does anyone know why? And how to make that happen? ...
5
2805
by: Silvio | last post by:
Here's my update statement: UPDATE Item1 SET reviewloop = 1, currentreviewstate=5 WHERE itemid in (SELECT itemid FROM Item2) The thing is: the table Item2 DOES NOT HAVE a field called...
1
1323
by: stapak | last post by:
I have a common (I guess) problem. I need to store my address book in format that would be independent on any e-mail clients - preferably in XML - to work sometimes on raw data. I tried to find...
5
1930
by: Simon Egginton | last post by:
Does anyone know how to make a CHAT ROOM for a webpage using java or jave script please. I am just look at you lot because i think you are the experts! THANK YOU! ewhost_simon"HI"@yahoo.co.uk...
8
2276
by: Neil Rowe | last post by:
Hi all I am writing an App at the moment and I need to be able to download & Upload xml files from an ftp server. Does anyone know how this can be done without using a third party component. ...
15
2551
by: Pucca | last post by:
I'm getting an error when I tried to use this BerConverter class in my C# code. Even though the Interent doc says that it runs on Win2000 sp4, I just thgouth I'll double check. Does anyone know...
1
2790
by: =?Utf-8?B?RWxpemFiZXRo?= | last post by:
I got a message that generic host process was connecting to the Internet. When I did Netstat, I saw four established connections from my computer to another port on my computer. What is going on? I...
13
2223
by: Anonymous | last post by:
On MS site: http://msdn2.microsoft.com/en-us/library/esew7y1w(VS.80).aspx is the following garbled rambling: "You can avoid exporting classes by defining a DLL that defines a class with...
1
2246
by: Clifford Robins | last post by:
Not wanting to reinvent the wheel, I found an image rotator on Code Project. Since it was based on tons of javacript, I thought it would be okay, since it was made into a web control, so all you had...
0
7124
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6998
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7200
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7375
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5460
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3090
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1416
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.