abcd+xyz
i want to split the 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!!
尝试:
String splits[] = org.split("\\+");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.