这可能过于复杂,但是干草......
我们需要做的第一件事就是删除所有我们不需要的垃圾......
String[] crap = {"(", ")", ",", ";"};
String text = "(123, 234; 345, 456) (567, 788; 899, 900)";
for (String replace : crap) {
text = text.replace(replace, " ").trim();
}
// This replaces any multiple spaces with a single space
while (text.contains(" ")) {
text = text.replace(" ", " ");
}
接下来,我们需要将字符串的各个元素分成更易于管理的形式
String[] values = text.split(" ");
接下来,我们需要将每个String
值对int
int[] iValues = new int[values.length];
for (int index = 0; index < values.length; index++) {
String sValue = values[index];
iValues[index] = Integer.parseInt(values[index].trim());
}
然后我们显示值...
for (int value : iValues) {
System.out.println(value);
}