Question and answer is powered by AnsPress.io
I have a string like Test$Test1.
Now while I am going to split it, It is not working.
String x=”Test$Test1″;
String[] strarray=x.split(“$”);
Log.e(TAG,strarray[0]);
But output is showing Test$Test1
Why this is heppening?
split()
takes in regex as an argument and $
is a metacharacter in Java regex API
. Therefore, you need to escape it:
Just simply do it.
String x=”Test$Test1″;
String[] strarray=x.split(“\$”);
Now log your out put.
Log.e(TAG,strarray[0]);