省市县拆分工具

/*** * 省市县拆分工具 * @param address * @return */ public static String subString(String address){ String i = ""; int provinceIndex = address.indexOf("省"); int cityIndex = address.indexOf("市"); String province=""; String city=""; String county=""; if(cityIndex>-1) { if(provinceIndex>-1) { province = address.substring(0, provinceIndex+1); city = address.substring(provinceIndex + 1, cityIndex+1); }else{ province = address.substring(0, cityIndex+1); city = address.substring(0, cityIndex+1); } county = address.substring(cityIndex + 1); if(StringUtils.isEmpty(county)) { county = city; } }else { if(provinceIndex>-1) { province = address.substring(0, provinceIndex+1); city = address.substring(0, provinceIndex+1); county = address.substring(provinceIndex + 1); if(StringUtils.isEmpty(county)) { county = province; } }else{ province = address; city = address; county = address; } } i=province+"/"+city+"/"+county; return i; }//省市县测试 public static void country(){ String address0 = "河南省开封市鼓楼区"; String address1 = "河南省"; String address2 = "开封市"; String address3 = "鼓楼区"; String address4 = "开封市鼓楼区"; String address5 = "河南省开封市"; String address6 = "河南省鼓楼区"; String address7 = "河南开封鼓楼"; String strValidDate0 = subString(address0); String strValidDate1 = subString(address1); String strValidDate2 = subString(address2); String strValidDate3 = subString(address3); String strValidDate4 = subString(address4); String strValidDate5 = subString(address5); String strValidDate6 = subString(address6); String strValidDate7 = subString(address7); System.out.println(strValidDate0); System.out.println(strValidDate1); System.out.println(strValidDate2); System.out.println(strValidDate3); System.out.println(strValidDate4); System.out.println(strValidDate5); System.out.println(strValidDate6); System.out.println(strValidDate7); }

    推荐阅读