//寻找文本
str.indexOf(".")
//获取指定位置字符串
String result = str.substring(0, 10);
分割版本
String[] sourceStrArray = sourceStr.split(
","
);
代码如下:
使用规则分割字符串
Pattern pen = Pattern.compile("\\|");
String slit = "广州一级,632|海南2,海口-桂林1,-广西";
String[] temp = pen.split(slit);System.out.println("我"+temp[0]+"----2"+temp[1]);
替换字符串
Pattern pen = Pattern.compile("\\|");
String slit = "广州一级,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);
下面是输出
广州一级,632----2海南2,海口-桂林1,-广西
广州一级,632&海南2,海口-桂林1,-广西