如何拆分字符串包括java中的一些点坐标?

时间:2015-01-13 07:59:33

标签: java

我有一个字符串如下,我想得到输出。我该怎么办?

输入:

String strconverted = "MULTIPOINT Z (116.356887145739 39.887461162166 -28.1861667136582,116.374615732553 39.8883537940982 125.380505711997)";

输出:

String pnt1= "116.356887145739 39.887461162166 -28.1861667136582"

String pnt2= "116.374615732553 39.8883537940982 125.380505711997"

请注意,可以" MULTIPOINT"有两点以上。

2 个答案:

答案 0 :(得分:1)

字符串拆分的简单解决方案是

String strconverted = "(116.356887145739 39.887461162166 -28.1861667136582,116.374615732553 39.8883537940982 125.380505711997)";
strconverted = strconverted.replace(")", "");
strconverted = strconverted.replace("(", "");

String[] parts = strconverted.split(",");

// parts[0] =  "116.356887145739 39.887461162166 -28.1861667136582"
// parts[0] =  "116.374615732553 39.8883537940982 125.380505711997"

答案 1 :(得分:1)

String strconverted = "MULTIPOINT Z (116.356887145739 39.887461162166 -28.1861667136582,116.374615732553 39.8883537940982 125.380505711997)";
String temp = strconverted.substring(strconverted.indexOf("(") + 1, strconverted.indexOf(")"));
String[] strArray = temp.split(",");

// parts[0] =  "116.356887145739 39.887461162166 -28.1861667136582"
// parts[1] =  "116.374615732553 39.8883537940982 125.380505711997"