62,615
社区成员
发帖
与我相关
我的任务
分享
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.Collection;
import java.util.ArrayList;
//正则表达式测试
public class RegularExpressionTest {
public static void main(String[] args) {
String waitToMatch1 = "141800Z --- NEAR 13.5N 137.7E";
Pattern pattern = Pattern.compile("\\d+.\\d+");
Matcher matcher = pattern.matcher(waitToMatch1);
printMatcher(matcher);
}
private static void printMatcher(Matcher matcher) {
ArrayList aClass = new ArrayList();
while (matcher.find()) {
//System.out.println(matcher.group());
aClass.add(matcher.group());
}
System.out.println(aClass);
}
}
String str = "141800Z --- NEAR 13.5N 137.7E";
String [] ss = str.split("([-a-zA-Z]\\s*)++");
public class s {
public static void main(String[] args) {
String s = "141800Z --- NEAR 13.5N 137.7E";
double[] d = new double[3];
int i = 0;
for (String ss : s.split("[^0-9.]")) {
if (!ss.equals("")) {
System.out.println(ss);
d[i++]=Double.valueOf(ss);
}
}
for(double dd:d)
System.out.println(dd);
}
}
141800
13.5
137.7
141800.0
13.5
137.7