如果用“(”作为分隔的话,必须是如下写法,String.split("\\("),这样才能正确的分隔开,不能用String.split("(");
如果用“)”作为分隔的话,必须是如下写法,String.split("\\)"),这样才能正确的分隔开,不能用String.split(")");
e.g.:
gravity_center = 'POINT(121.874850835107 28.4559363140394)';
String[] gravity_center_array = gravity_center.split("\\(");
System.out.println("result1");
for (int i = 0; i < gravity_center_array.length; i++) {
System.out.println("gravity_center_array"+i +"="+ gravity_center_array[i]);
}
String[] gravity_center_array1 = gravity_center_array[1].split(" ");
for (int i = 0; i < gravity_center_array1.length; i++) {
System.out.println("gravity_center_array1"+i+"=" + gravity_center_array1[i]);
}
lon = gravity_center_array1[0];
System.out.println("lon ="+ lon); // lon = 121.874850835107
String[] gravity_center_array2 = gravity_center_array1[1].split("\\)");
for (int i = 0; i < gravity_center_array2.length; i++) {
System.out.println("gravity_center_array2"+i+"=" + gravity_center_array2[i]);
}
lat = gravity_center_array2[0];
System.out.println("lat ="+ lat);// lat =28.4559363140394