I have an Android app that retrieves values from a servers database and displays them in the app but carriage returns are coming back as \\n but I need them to act as carriage that will place text below onto a new line.
I first post data to my server to store in database like this:
$body = mysqli_real_escape_string($conn, $_POST['body']);
Then I encrypt the text before storing in database like this
$encryptedBodyText = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $body, MCRYPT_MODE_CBC, md5(md5($key))));
I now get the data from the database and then JSON it to android
$decryptedBody = trim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($body), MCRYPT_MODE_CBC, md5(md5($key))), "\0");
but when I show this data in the android the new lines are shown as \\n instead of actual new lines.
How can I replace the \\n so they are actual new lines in java
I've tried
String t = sharedBodyText.replace("\n",System.getProperty("line.separator"));
bodyText.setText(t);
and it doesn't work but if I change to
String t = sharedBodyText.replace("gg",System.getProperty("line.separator"));
bodyText.setText(t);
it does work if there is "gg" in the body text
How about replacing \\n
with System.getProperty("line.separator")
in Android side
Try this:
text.replaceAll("\n", System.getProperty("line.separator"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.