现需要写一个拆分身份证住址的方法,需求如下1. 先拆出以省(直辖市、自治区)开头的信息2. 第二步拆出市(直辖市对应的为区)一级的信息3. 第三部拆出区(或者县)一级的信息4. 第四步拆出具体的住址。5. 此方法返回类型为string[]
如身份证信息为:    北京市海淀区中关村东大街***********
    拆分后的效果为:
        string[0] = "北京市";
        string[1] = "海淀区";
        string[2] = "中关村东大街***********";    山东省济南市历下区***********
    拆分后的效果为:
        string[0] = "山东省";
        string[1] = "济南市";
        string[2] = "历下区";
        string[3] = "***********";    广西壮族自治区桂林市象山区***********
    拆分后的效果为:
        string[0] = "广西壮族自治区";
        string[1] = "桂林市";
        string[2] = "象山区";
        string[3] = "***********";请各位高手帮帮忙,谢谢!

解决方案 »

  1.   

    string 方法 IndexOf SubString 等
    应该可以了
    你给个例子
      

  2.   

    你可以用看看他们之间有没有必要的逻辑,比如,国,省,市,区,县,镇,乡,村,‘国’是最大的一级,先按照国家来split(‘国’)一下,可以得到两个字符串,那么将国家的那个字符串提出来放到数组里面,然后在将另一段字符串split(‘省’)一次,这样能得到省,然后在将没有包含省的字符串继续split(‘市’),依次类推,直到推到‘村’,为止,这个思路或许可以解决当前问题,但是需要改进,可能有些村名,或者乡镇的名字会包含“国”或者“省”这些字眼,你多加几个判断,
      

  3.   


                string str = "北京市海淀区中关村东大街";            List<string> list = new List<string>();            
                char[] cs = new char[] { '省', '市', '区', '县' };
                for (int i = 0; i < cs.Length; i++)
                {
                    str = str.Replace(cs[i].ToString(), cs[i].ToString() + "|");
                }            string[] ss = str.Split(new char[]{'|'},StringSplitOptions.RemoveEmptyEntries);            foreach (string s in ss)
                    Console.WriteLine(s);
      

  4.   

    char[] cs = new char[] { '省', '市', '区', '县' };
    //我只写了你提到的区域级别...如果有别的,自己加到cs中即可
      

  5.   


    xx省,省前至少有一字

    xx市,市前至少有一字
    xx路,路钱至少有一字东街市路,拆为东街,后市前无字,应为东街市,后路前无字,应为东街市路。
      

  6.   

    下一个行政区划表,然后按省市区逐级遍历找到StartWith的项目,最后剩下的是地址
    如果地址名称不规范,遍历不到,就只能按省市区县等关键字来尝试分割了
    不知道这样行不行?
      

  7.   

    \b(?<province>\w+?(?:省|自治区))?(?<city>\w+?市)(?<street>.+)(?= |$)取province、city、street分组。Match m = Regex.Match("北京市海淀区中关村东大街***********",@"\b(?<province>\w+?(?:省|自治区))?(?<city>\w+?市)(?<street>.+)(?= |$)");Console.WriteLine(m.Groups["province"].Value);
    Console.WriteLine(m.Groups["city"].Value);
    Console.WriteLine(m.Groups["street"].Value);
      

  8.   

    额,做的到吗?自己google 中国国家期刊网,看看上面都多少个863计划,火炬计划,XXX重点科技计划 是关于模式匹配滴这东西就是中科院那拨人都不见得能很好解决想想看google当初和GOV的主要分歧是啥,工信部又凭啥给绿坝4000w。 模式匹配这东西可不是上面那个正则表达式就能简简单单的搞定的(真这么简单,google就不会退出了,那个4000w你都可以拿下了)
      

  9.   

    string str = "北京市海淀区中关村东大街";            List<string> list = new List<string>();            
                char[] cs = new char[] { '省', '市', '区', '县' };
                for (int i = 0; i < cs.Length; i++)
                {
                    str = str.Replace(cs[i].ToString(), cs[i].ToString() + "|");
                }            string[] ss = str.Split(new char[]{'|'},StringSplitOptions.RemoveEmptyEntries);            foreach (string s in ss)
                    Console.WriteLine(s);
      

  10.   

    这也是难点?证件号前6位是地区码,2位省份,2位地市,2位区县
    省份=idcard.substring(0,2)
    地市=idcard.substring(2,2)
    区县=idcard.substring(4,2)
      

  11.   

    具体的编码与地址名称是个很大的字典表,我有省份的,其他的自己找吧
                if (aProv[int.Parse(idcard.Substring(0, 2))] == null)
                {
                    info = "公民身份证号前两位不正确,不正确的地区码";
                    return result;
                }
    省份如下:
                string[] aProv = new string[] { null, null, null, null, null, null, null, null, null, null, 
                                                null, "北京", "天津", "河北", "山西", "内蒙古", null, null, null, null, 
                                                null, "辽宁", "吉林", "黑龙江", null, null, null, null, null, null, 
                                                null, "上海", "江苏", "浙江", "安微", "福建", "江西", "山东", null, null, 
                                                null, "河南", "湖北", "湖南", "广东", "广西", "海南", null, null, null, 
                                                "重庆", "四川", "贵州", "云南", "西藏", null, null, null, null, null, null, 
                                                "陕西", "甘肃", "青海", "宁夏", "新疆", null, null, null, null, null, 
                                                "台湾", null, null, null, null, null, null, null, null, null, 
                                                "香港", "澳门", null, null, null, null, null, null, null, null, 
                                                "国外", null, null, null, null, null, null, null, null, null};
      

  12.   

    这个真不好办,用身份证号码吧,先用身份证号码确定大概位置,再用模式匹配或者用string中的方法找出街道,住址。。比如从身份证号码里面确定了是山东省济南市历下区,那么在吧这个与详细住址对比,在案相关字段进行分割,貌似应该就可以了