开发者

Java - How to split a string on plus signs?

I was trying to split an arithmetic expression (eg "1+2+10+15") on the plus signs. However, I didn't manage to write the appropriate r开发者_Python百科egular expression. I thought this would work:

expression.split("\\+");

but it doesn't. Do you know the correct solution?


It does. However split(...) returns an array, it does not "transform" your String into a String[]. Try this:

String expression = "1+2+10+1";
String[] tokens = expression.split("\\+");


this way

expression.split("[+]");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜