Solved

Parse Street Address

Posted on 2010-11-10
13
1,142 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
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
 

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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Disable and re-enable a dynamic System.Timers.Timer 6 39
Error in page 3 44
Run time Error 4 34
Entity Framework 7 27
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
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 video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 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

12 Experts available now in Live!

Get 1:1 Help Now