Reputation: 23
I have a string "Rush to ER/F07^e80c801e-ee37-4af8-9f12-af2d0e58e341". I want to split it into 2 strings on the delimiter ^. For example string str1=Rush to ER/F07 and String str2 = e80c801e-ee37-4af8-9f12-af2d0e58e341
For getting this i am doing splitting of the string , I followed the tutorial on stackoverflow but it is not working for me , here is a code
String[] str_array = message.split("^");
String stringa = str_array[0];
String stringb = str_array[1];
when I am printing these 2 strings I am getting nothing in stringa and in stringb I am getting all the string as it was before the delimiter.
Please help me
Upvotes: 0
Views: 155
Reputation: 1754
You have to escape special regex sign via \\
try this:
String[] str_array = message.split("\\^");
Upvotes: 6
Reputation: 627087
It is because the .split()
method requires a regex pattern. Escape the ^:
String[] str_array = message.split("\\^");
You can get more information on this at http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#split-java.lang.String-.
Upvotes: 1