请原谅我,如果我已经问过一个已经回答的问题,但我不确定这是一个初学者的最好方法。
我有一个像下面这样的字符串,什么是转换此字符串的最佳方式,以便我只有双打3.4134388041,0.63117288等我丢弃其余的?
谢谢!
Shading:Building:Detailed,
39, !- Name
, !- Transmittance Schedule Name
4, !- Number of Vertices
3.4134388041, !- Vertex 1 X-coordinate {m}
0.63117288, !- Vertex 1 Y-coordinate {m}
2.2012378517, !- Vertex 1 Z-coordinate {m}
3.4134388041, !- Vertex 2 X-coordinate {m}
10.01517288, !- Vertex 2 Y-coordinate {m}
2.2012378517, !- Vertex 2 Z-coordinate {m}
2.9134388041, !- Vertex 3 X-coordinate {m}
10.01517288, !- Vertex 3 Y-coordinate {m}
2.2012378517, !- Vertex 3 Z-coordinate {m}
2.9134388041, !- Vertex 4 X-coordinate {m}
0.63117288, !- Vertex 4 Y-coordinate {m}
2.2012378517; !- Vertex 4 Z-coordinate {m}
答案 0 :(得分:0)
以下代码应隔离字符串中不能完全被1整除的每个数字,分别打印出来:
public static void main(String[] args)
{
String text = ""; // string was too long to fit here for tidiness
Matcher search = Pattern.compile("(?!=\\d\\.\\d\\.)([\\d.]+)").matcher(text);
while (search.find())
{
double doub = Double.parseDouble(search.group(1));
if (doub mod 1 != 0)
{
System.out.println(doub);
}
}
}