0

I'm receiving a string from a windows application, the string is like this:

"some text\r\nsome other text"

When I display the string in an alert dialog I see the following:

"some textrnsome other text"

The same string is showing correctly on a TextView, but not in an AlertDialog.

Please advice what I should do.

Best Regards.

Edit This is what I tried so far:

CustomDialog.Builder dialog = new CustomDialog.Builder(this, "", getString(R.string.ok));
    dialog.contentColor(getResources().getColor(R.color.content_color));
    dialog.titleColor(getResources().getColor(R.color.content_color));
    dialog.positiveColor(getResources().getColor(R.color.cpb_red));
    dialog.content(Message.replace("\r\n", "\n"));
    dialog.build().show();

Edit 2: Let me explain more, I receive a JSON response from a WCF Service on Windows, parse JSON using FastJson the text I receive from JSON after parsing is

Server Will\r\n be down for maintenance

We just added \r\n for testing purpose but I'm sure someone will use them when sending data to Android. I have tried replacing using replace function, but no success.

JustADev
  • 258
  • 1
  • 8
  • 19

1 Answers1

0

Escaping the backslash in a String#replaceAll call works for me

String text = "some text\r\nsome other text";
System.out.println("preprocess text: " + text);
String post = text.replaceAll("\\r\\n", ":");
System.out.println("postprocess text: " + post);

Produces:

preprocess text: some text
some other text
postprocess text: some text:some other text
JBirdVegas
  • 10,855
  • 2
  • 44
  • 50
  • This didn't work, I even used Log.d and println I still see the same text I posted in my question. Ironically the same text works on an iPhone without having to replace anything :-/ – JustADev Oct 23 '15 at 06:24