Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split String with .(dot) character java android [duplicate]

People also ask

Can we split a string with dot in Java?

To split a string with dot, use the split() method in Java. str. split("[.]", 0); The following is the complete example.

Why split is not working for dot in Java?

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.

How do you separate text on Android?

split() is documented with TextUtils. split(): String. split() returns [''] when the string to be split is empty.

What does split \\ s+ do in Java?

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