代碼如下:
使用規(guī)則分割字符串
Pattern pen = Pattern.compile("\\|");
String slit = "廣州一級(jí),632|海南2,???桂林1,-廣西";
String[] temp = pen.split(slit);System.out.println("我"+temp[0]+"----2"+temp[1]);
替換字符串
Pattern pen = Pattern.compile("\\|");
String slit = "廣州一級(jí),632|海南2,海口-桂林1,-廣西";
String[] temp = pen.split(slit);
System.out.println("我"+temp[0]+"----2"+temp[1]);
String newString = slit.toString().replace("|","&");
System.out.println("我=="+newString);
下面是輸出
廣州一級(jí),632----2海南2,???桂林1,-廣西
廣州一級(jí),632&海南2,???桂林1,-廣西