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("[+]");
精彩评论