开发者

Split the string

abcd+xyz

i want to split th开发者_StackOverflow社区e string and get left and right components with respect to "+"

that is i need to get abcd and xyz seperatly. I tried the below code.

String org  = "abcd+xyz";   
String splits[] = org.split("+");

But i am getting null value for splits[0] and splits[1]...

Please help..


The string you send as an argument to split() is interpreted as a regex (documentation for split(String regex)). You should add an escape character before the + sign:

String splits[] = org.split("\\+");

You might also find the Summary of regular-expression constructs worth reading :)


"+" is wild character for regular expression. So just do

String splits[] = org.split("\\+");

This will work


the expression "+" means one or many in java regular expression. split takes Regex as a argument hence the comparion given by you fails So use

String org = "abcd+xyz";
String splits[] = org.split(""\+");

regards!!


Try:

String splits[] = org.split("\\+");
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜