To split a string with dot, use the split() method in Java. str. split("[.]", 0); The following is the complete example.
backslash-dot is invalid because Java doesn't need to escape the dot. You've got to escape the escape character to get it as far as the regex which is used to split the string.
split() is documented with TextUtils. split(): String. split() returns [''] when the string to be split is empty.
split("\\s+") will split the string into string of array with separator as space or multiple spaces. \s+ is a regular expression for one or more spaces.
You need to escape .
using \
Eg:
String s="Android_a_b.pdf";
String[] parts = s.split("\\."); // escape .
String part1 = parts[0];
String part2 = parts[1];
Now it will split by .
Split(regex) in Java
Splits this string around matches of the given regular expression.
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array.
Keep in mind that
Parameters: regex - the delimiting regular expression
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