?
Solved

Parse Street Address

Posted on 2010-11-10
13
Medium Priority
?
1,227 Views
Last Modified: 2012-05-10
I want to parse an address from a text field.
for example

string = 123 test street, mountain view, CA 91302

to seperate variables

Output

Street Address
City
State
Zip

If anyone knows how to do this I'd greatly appreciate the help
0
Comment
Question by:TheWebGuy38
  • 8
  • 4
12 Comments
 
LVL 8

Expert Comment

by:guvera
ID: 34109154
Hi,

The function is from this link:
http://www.4guysfromrolla.com/ASPScripts/PrintPage.asp?REF=%2Fwebtech%2F120400-1.3.shtml


Dim TestString,arrTest,x

TestString = "123, 'Bill', 'is rocking', 'what, ok you are right'"

arrTest = SplitAdv(TestString)

For x = 0 to Ubound(arrTest)
   MsgBox arrTest(x)
Next


Function SplitAdv(strInput)
Dim objRE
Set objRE = CreateObject("VBScript.RegExp")
objRE.IgnoreCase = true
objRE.Global = true
objRE.Pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
End Function

The above code is already put it by our experts. Chk the below link also that what u expected.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21935286.html

Hope that helps to you!!
0
 
LVL 8

Expert Comment

by:guvera
ID: 34109427
Hi TheWebGuy38,

 Did you check the above code?? Getting anything??

Thanks
0
 

Author Comment

by:TheWebGuy38
ID: 34109446
Having some problems getting it working.  it's asp.net

this is my code. sorry, a little messy
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim Addressstring = TextBox1.Text

        Dim TestString, arrTest, x

        TestString = "123, 'Bill', 'is rocking', 'what, ok you are right'"

        arrTest = SplitAdv(TestString)

        'For x = 0 To UBound(arrTest)
        'MsgBox(arrTest(x))
        'Next
        Response.Write(arrTest)

        'Label1.Text = arrTest

    End Sub

    Function SplitAdv(ByVal strInput As String) As Array
        Dim objRE
        objRE = CreateObject("VBScript.RegExp")
        objRE.IgnoreCase = True
        objRE.Global = True
        objRE.Pattern = ",(?=([^']*'[^']*')*(?![^']*'))"
        SplitAdv = Split(objRE.Replace(strInput, "\b"), "\b")
    End Function

Open in new window

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:TheWebGuy38
ID: 34109451
err changed

For x = 0 To UBound(arrTest)
           
            Response.Write(arrTest)
        Next

but this is what the response write gives me

"System.String[]System.String[]System.String[]System.String[] "
0
 
LVL 8

Expert Comment

by:guvera
ID: 34109552
Hi,
Chk the change of below code

Dim X

  For x = 0 To UBound(arrTest)
            MsgBox(arrTest(x))
            Response.Write(arrTest(x))
        Next
0
 

Author Comment

by:TheWebGuy38
ID: 34117827
I think the msgbox is for vb.net apps isn't it?

this is webcode
0
 
LVL 8

Expert Comment

by:guvera
ID: 34118002
yes you dont put Msgbox. Execute in vb script you can write document.write instead of Response.Write. It is working. If you have any clarification let me know.
0
 

Author Comment

by:TheWebGuy38
ID: 34118190
I think that's java? need vbscript.

but shouldn't response.write work?
0
 

Author Comment

by:TheWebGuy38
ID: 34254501
Anyone have any other ideas?
0
 

Accepted Solution

by:
TheWebGuy38 earned 0 total points
ID: 34419926
Have the solution myself, lol

here it is.
Public Function ParseAddress(ByVal AddressInput As String) As Collection


        Dim colAddressInputs As New Collection
        Try
            If (Not String.IsNullOrEmpty(AddressInput)) Then

                Dim strAddresses As New ArrayList
                Dim separator() As Char = {","}
                Dim strAddress1Inputs() As String = AddressInput.Split(separator, 3)
                If (strAddress1Inputs.Length > 0) Then
                    strAddresses.Add(strAddress1Inputs(0))
                End If
                If (strAddress1Inputs.Length > 1) Then
                    strAddresses.Add(strAddress1Inputs(1))
                End If

                If (strAddress1Inputs.Length > 2) Then

                    Dim separators() As Char = {",", ".", " "}
                    Dim strAddress2Inputs() As String = strAddress1Inputs(2).Split(separators)

                    If (strAddress2Inputs.Length > 1) Then
                        Dim strState As String = String.Empty
                        For i As Integer = 0 To strAddress2Inputs.Length - 2
                            strState = strState + strAddress2Inputs(i) + " "
                        Next
                        strAddresses.Add(strState.Trim())
                        strAddresses.Add(strAddress2Inputs(strAddress2Inputs.Length - 1))
                    Else
                        If (strAddress2Inputs.Length > 0) Then
                            strAddresses.Add(strAddress2Inputs(0))
                        End If

                    End If
                End If

                For Each strAddress As String In strAddresses
                    If (Not String.IsNullOrEmpty(strAddress)) Then
                        If (IsCity(strAddress.Trim()) AndAlso (Not colAddressInputs.Contains("City"))) Then
                            colAddressInputs.Add(Trim(strAddress), "City")
                        ElseIf (IsState(strAddress.Trim()) AndAlso (Not colAddressInputs.Contains("State"))) Then
                            colAddressInputs.Add(Trim(strAddress), "State")
                        ElseIf (IsNumeric(strAddress.Trim()) AndAlso (Not colAddressInputs.Contains("Zip"))) Then
                            colAddressInputs.Add(Trim(strAddress), "Zip")
                        ElseIf (Not colAddressInputs.Contains("Address")) Then
                            colAddressInputs.Add(Trim(strAddress), "Address")
                        End If
                    End If
                Next
                If ((Not colAddressInputs.Contains("City"))) Then
                    colAddressInputs.Add("", "City")
                End If
                If ((Not colAddressInputs.Contains("State"))) Then
                    colAddressInputs.Add("", "State")
                End If
                If ((Not colAddressInputs.Contains("Zip"))) Then
                    colAddressInputs.Add("", "Zip")
                End If
                If (Not colAddressInputs.Contains("Address")) Then
                    colAddressInputs.Add("", "Address")
                End If
            Else
                colAddressInputs.Add("", "City")
                colAddressInputs.Add("", "State")
                colAddressInputs.Add("", "Zip")
                colAddressInputs.Add("", "Address")
            End If
        Catch ex As Exception

        End Try
        Return colAddressInputs

    End Function

    Public Function IsCity(ByVal strCity As String) As Boolean
        Try
            Using cn As New SqlConnection(WebConfigurationManager.ConnectionStrings("SQLDbconn").ConnectionString)
                Dim cmd As New SqlCommand("SELECT COUNT(*) FROM Cities where City ='" + strCity + "' or Code='" + strCity + "'", cn)
                cn.Open()
                Dim intResult As Integer = cmd.ExecuteScalar()
                If (intResult > 0) Then
                    Return True
                Else
                    Return False

                End If
            End Using

        Catch ex As Exception
            Return False
        End Try
    End Function
    Public Function IsState(ByVal strState As String) As Boolean
        Try
            Using cn As New SqlConnection(WebConfigurationManager.ConnectionStrings("SQLDbconn").ConnectionString)
                Dim cmd As New SqlCommand("SELECT COUNT(*) FROM Regions where Region ='" + strState + "' or Code='" + strState + "'", cn)
                cn.Open()
                Dim intResult As Integer = cmd.ExecuteScalar()
                If (intResult > 0) Then
                    Return True
                Else
                    Return False

                End If
            End Using

        Catch ex As Exception
            Return False
        End Try
    End Function

Open in new window

0
 

Author Comment

by:TheWebGuy38
ID: 34426092
I have posted the answer
0
 

Author Closing Comment

by:TheWebGuy38
ID: 34447386
Enjoy
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question