유틸리티 서비스 주소를 다루는 응용 프로그램은 현재 사용자가 주소 부분을 분리하고 데이터베이스에 추가하기 전에 적절한 필드에 넣을 수있을만큼 충분히 알도록하고 있습니다. 직선 알파벳순 정렬은 주소에 사전 방향이있을 때 항상 올바르지 않기 때문에 정렬 목적으로이 방법을 수행해야합니다. 예를 들어, 현재 사용자가 서비스 주소 (123) N 주 세인트을 넣어 원한다면, 그들은 그것을 입력하면 같은 : = 123 서비스 주소의 부분을 분류하는 정규식?
- 거리 번호 = 홈페이지
- 스트리트 형 = 세인트는
나는 스플릿 (Split) 기능을 사용하여 각 부분을 반복하여 부분으로이 주소를 분리하는 시도했습니다. 내가 지금까지 가지고있는 것은 아래와 같다 :
Public Shared Function ParseServiceAddress(ByVal Address As String) As String() 'this assumes a valid address - 101 N Main St South Dim strResult(5) As String '0=st_num, 1=predir, 2=st_name, 3=st_type, 4=postdir Dim strParts() As String Dim strSep() As Char = {Char.Parse(" ")} Dim i As Integer Dim j As Integer = 0 Address = Address.Trim() strParts = Address.Split(strSep) 'split using spaces For i = 0 To strParts.GetUpperBound(0) If Integer.TryParse(strParts(i), j) Then 'this is a number, is it the house number? If i = 0 Then 'we know this is the house number strResult(0) = strParts(i) Else 'part of the street name strResult(2) = strResult(2) & " " & strParts(i) End If Else Select Case strParts(i).ToUpper() Case "TH", "ND" 'know this is part of the street name strResult(2) = strResult(2) & strParts(i) Case "NORTH", "SOUTH", "EAST", "WEST", "N", "S", "E", "W" 'is this a predirection? If i = 1 Then strResult(1) = strParts(i) ElseIf i = strParts.GetUpperBound(0) Then 'this is the post direction strResult(4) = strParts(i) Else 'part of the name strResult(2) = strResult(2) & strParts(i) End If Case Else If i = strParts.GetUpperBound(0) Then 'street type strResult(3) = strParts(i) Else 'part of the street name strResult(2) = strResult(2) & " " & strResult(i) End If End Select End If Next i Return strResult End Function나는이 방법이 성가신, 천천히, 그리고 심지어 우키 한 주소가 주어 졌을 때 완전히 틀린 것을 알았다. 나는 여기서 뭘 하려는지 정규 표현식에 대한 좋은 응용 프로그램이 될 것이라고 궁금하네요? 틀림없이 나는 이전에 어떤 정규식을 사용 해본 적이 없으며 그 점에서 전체 초보자입니다.
도움을 주셔서 감사합니다. :)
편집 - 필자는 정규 표현식뿐만 아니라 파서가 필요해 보인다. 누구든지 .NET에서 좋은 주소 파서 라이브러리를 알고 있습니까? 우리 자신의 카드를 쓰는 것은 지금 카드에 없으며 카드가 나온다면 뒤의 버너에게 보내질 것입니다.
미리보기는 항상 한 글자입니까? –
@Stuart B - 아니요, 때로는 사람들이 "123 South Main St"와 같은 문자를 입력합니다 –
@Heather -이 어려운 문제는 확실히 더 털이 있습니다! 당신은 분명히 받아 들여질 수있는 사전 목록을 정의해야합니다. –