Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String replace function not working in android

Tags:

java

android

I used the following code to replace occurrence of '\' but its not working.

msg="\uD83D\uDE0A";
msg=msg.replace("\\", "|");

I spent a lot of time in Google. But didn't find any solution.

Also tried

msg="\uD83D\uDE0A";
msg=msg.replace("\", "|");
like image 477
Jarish Jose Avatar asked Jun 08 '15 10:06

Jarish Jose


1 Answers

The msg string defined must also use an escape character like this:

msg="\\uD83D\\uDE0A";
msg=msg.replace("\\", "|");

That code will work and it will result in: |uD83D|uDE0A

like image 194
reidzeibel Avatar answered Sep 27 '22 23:09

reidzeibel