以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助]如何分离地理位置 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=85241) |
-- 作者:新航程小何 -- 发布时间:2016/5/21 8:09:00 -- [求助]如何分离地理位置 各位老师,这是我写的一个分离具体地理位置的代码,运行时正常的,但就是觉得有点麻烦,而且不严谨,不知道有么有简答的解决方法 Dim addr As String="甘肃省兰州市安宁区马家镇银滩路街道" Dim prov As String Dim City As String Dim Town As String Dim cntsd As String Dim cnt As String If addr.contains("省") Prov =addr.Substring(0,addr.Indexof("省")+1) If addr.contains("市") City=addr.Substring(addr.Indexof("省")+1,addr.Indexof("市")-addr.Indexof("省")) If addr.contains("区") Town=addr.Substring(addr.Indexof("市")+1,addr.Indexof("区")-addr.Indexof("市")) If addr.contains("乡") cntsd=addr.Substring(addr.Indexof("县")+1,addr.Indexof("乡")-addr.Indexof("县")) If addr.contains("村") cnt=addr.Substring(addr.Indexof("乡")+1,addr.Indexof("村")-addr.Indexof("乡")) ElseIf addr.contains("街道") cnt=addr.Substring(addr.Indexof("乡")+1,addr.Indexof("街道")-addr.Indexof("乡")) End If ElseIf addr.contains("镇") cntsd=addr.Substring(addr.Indexof("县")+1,addr.Indexof("镇")-addr.Indexof("县")) If addr.contains("村") cnt=addr.Substring(addr.Indexof("镇")+1,addr.Indexof("村")-addr.Indexof("镇")) ElseIf addr.contains("街道") cnt=addr.Substring(addr.Indexof("镇")+1,addr.Indexof("街道")-addr.Indexof("镇")) End If End If ElseIf addr.contains("县") Town=addr.Substring(addr.Indexof("市")+1,addr.Indexof("县")-addr.Indexof("市")) If addr.contains("乡") cntsd=addr.Substring(addr.Indexof("县")+1,addr.Indexof("乡")-addr.Indexof("县")) If addr.contains("村") cnt=addr.Substring(addr.Indexof("乡")+1,addr.Indexof("村")-addr.Indexof("乡")) ElseIf addr.contains("街道") cnt=addr.Substring(addr.Indexof("乡")+1,addr.Indexof("街道")-addr.Indexof("乡")) End If ElseIf addr.contains("镇") cntsd=addr.Substring(addr.Indexof("县")+1,addr.Indexof("镇")-addr.Indexof("县")) If addr.contains("村") cnt=addr.Substring(addr.Indexof("镇")+1,addr.Indexof("村")-addr.Indexof("乡")) ElseIf addr.contains("街道") cnt=addr.Substring(addr.Indexof("镇")+1,addr.Indexof("街道")-addr.Indexof("乡")) End If End If End If End If End If output.show(prov & City & Town & cntsd & cnt) |
-- 作者:逛逛 -- 发布时间:2016/5/21 10:05:00 -- Dim s As String="甘肃省兰州市安宁区马家镇银滩路街道" Dim l() As String = {"省","市","区","县","乡","镇","村","街道"} Dim li As new List(of String) For i As Integer = 0 To l.Length - 1 If s.contains(l(i)) Then li.Add(l(i)) Next If li.Count = 0 Then Return Nothing Dim strRegex As String = "^" For Each ss As String In li strRegex += "(?<" & ss & ">\\w+)" & ss & "+" Next Dim r As New System.Text.RegularExpressions.Regex(strRegex.TrimEnd("+")) For Each ss As String In li Output.show(r.Match(s).Result("${" & ss & "}") & ss) Next |
-- 作者:Hyphen -- 发布时间:2016/5/21 11:30:00 -- Dim s As String="甘肃省兰州市安宁区马家镇银滩路街道" Dim p As String = "([省市区县乡镇村])" Dim p2 As String = "([省市区县乡镇村]|街道|街)" Dim r As New System.Text.RegularExpressions.Regex(p) Dim str = r.Split(s) For Each a As String In str Output.Show(a) Next
|
-- 作者:新航程小何 -- 发布时间:2016/5/30 20:21:00 -- 多谢 |