[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Parse Street Address

Posted on 2010-11-10
13
Medium Priority
?
1,217 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
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

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

656 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