I want to split a string when following of the symbols encounter "+,-,*,/,=" I am using split function but this function can take only one argument.Moreover it is not working on "+". I am using following code:-
Stringname.split("Symbol");
Thanks.
String.split
takes a regular expression as argument.
This means you can alternate whatever symbol or text abstraction in one parameter in order to split your String
.
See documentation here.
Here's an example in your case:
String toSplit = "a+b-c*d/e=f";
String[] splitted = toSplit.split("[-+*/=]");
for (String split: splitted) {
System.out.println(split);
}
Output:
a
b
c
d
e
f
Notes:
Pattern
s must be double-escaped with \\
. Edit: Not needed here. []
brackets in the pattern indicate a character class.Pattern
s here.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With