I have a String something like this
"myValue"."Folder"."FolderCentury";
I want to split from dot("."). I was trying with the below code:
String a = column.replace("\"", "");
String columnArray[] = a.split(".");
But columnArray
is coming empty. What I am doing wrong here?
I will want to add one more thing here someone its possible String array object will contain spitted value like mentioned below only two object rather than three.?
columnArray[0]= "myValue"."Folder";
columnArray[1]= "FolderCentury";
Note that String#split
takes a regex.
You need to escape the special char .
(That means "any character"):
String columnArray[] = a.split("\\.");
(Escaping a regex is done by \
, but in Java, \
is written as \\
).
You can also use Pattern#quote
:
Returns a literal pattern String for the specified String.
String columnArray[] = a.split(Pattern.quote("."));
By escaping the regex, you tell the compiler to treat the .
as the string .
and not the special char .
.
split() accepts an regular expression. So you need to skip '.' to not consider it as a regex meta character.
String[] columnArray = a.split("\\.");
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