Solved

Parse Street Address

Posted on 2010-11-10
13
1,128 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
13 Comments
 
LVL 8

Expert Comment

by:guvera
Comment Utility
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
Comment Utility
Hi TheWebGuy38,

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

Thanks
0
 

Author Comment

by:TheWebGuy38
Comment Utility
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
 

Author Comment

by:TheWebGuy38
Comment Utility
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
Comment Utility
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
Comment Utility
I think the msgbox is for vb.net apps isn't it?

this is webcode
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 8

Expert Comment

by:guvera
Comment Utility
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
Comment Utility
I think that's java? need vbscript.

but shouldn't response.write work?
0
 

Author Comment

by:TheWebGuy38
Comment Utility
Anyone have any other ideas?
0
 

Accepted Solution

by:
TheWebGuy38 earned 0 total points
Comment Utility
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
Comment Utility
I have posted the answer
0
 

Author Closing Comment

by:TheWebGuy38
Comment Utility
Enjoy
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now