【发布时间】:2013-03-30 01:35:48
【问题描述】:
我知道如何用空格等特殊字符分割字符串:
String numbers = "22 14 10 8 70";
int [] n1 = new int [numbers.length()];
for(int n = 0; n < numbers.length(); n++) {
n1[n] = Integer.parseInt(numbers.split(" ")[n]);
}
但我想用任何非数字(也包括负号和浮点)类型的字符来分割字符串;像这样的字符串:
String numbers = "22+14/10*8-70";
【问题讨论】:
-
正则表达式不是解决这个问题的方法。
-
@LuiggiMendoza 我从标签中删除正则表达式
-
String.split() 可以拆分正则表达式字符串
-
@jedwards 这看起来像公式解析,而正则表达式不是要走的路。