?
Solved

Parse Street Address

Posted on 2010-11-10
13
Medium Priority
?
1,208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
13 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
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 

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

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

764 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