身份证的前6位就是表示开出身份证所在地的区划代码。
图:
类:
Public Class RegionalclassClass Regionalclass
Private _Regionals As RegionalCollection
Private File As String = System.AppDomain.CurrentDomain.BaseDirectory & "\全国行政区划代码.txt"
Private IsOK As Boolean = False
Public ReadOnly Property ItemsCollection()Property ItemsCollection() As RegionalCollection
Get
Return _Regionals
End Get
End Property
Public Sub Load()Sub Load()
IsOK = System.IO.File.Exists(File)
If Not IsOK Then
MsgBox("文件不存在!")
Exit Sub
End If
_Regionals = New RegionalCollection
Dim fs As IO.FileStream = New IO.FileStream(File, IO.FileMode.Open)
Dim sr As IO.StreamReader = New IO.StreamReader(fs, System.Text.Encoding.Default)
Dim Line As String
Dim tmp As Regional
Dim tmp1 As Regional
Dim tmp2 As Regional
While sr.Peek <> -1
Line = sr.ReadLine
If Line.Length > 6 Then
If Char.IsNumber(Line, 0) AndAlso Char.IsNumber(Line, 5) Then
tmp = New Regional(Line.Substring(0, 6), Line.Substring(6).Trim)
If tmp.Code.Substring(4) = "00" Then '第五、第六位是0
If tmp.Code.Substring(2, 2) = "00" Then '第三、四位是0
'代表省
tmp.FullName = tmp.Name
Else
'其中01-20、51-70表示省直辖市,21-50表示地区(州、盟)
tmp1 = _Regionals.Item(tmp.Code.Substring(0, 2) & "0000")
If Not tmp1 Is Nothing Then
tmp.FullName = tmp1.Name & tmp.Name
End If
End If
Else
'01-18表示市辖区或地辖区,21-80表示县(旗),81-99表示省直辖县级市
tmp1 = _Regionals.Item(tmp.Code.Substring(0, 2) & "0000")
If Not tmp1 Is Nothing Then
If tmp1.Name.Substring(tmp1.Name.Length - 1).Equals("市") Then
tmp.FullName = tmp1.FullName & tmp.Name
Else
tmp2 = _Regionals.Item(tmp.Code.Substring(0, 4) & "00")
If Not tmp2 Is Nothing Then
tmp.FullName = tmp2.FullName & tmp.Name
End If
End If
End If
End If
_Regionals.Add(tmp)
End If
End If
End While
sr.Close()
fs.Close()
End Sub
Public Class RegionalCollectionClass RegionalCollection
Inherits System.Collections.DictionaryBase
Public Sub Add()Sub Add(ByVal iItem As Regional)
&