0

我从 Windows 应用程序接收一个字符串,该字符串是这样的:

“一些文本\r\n一些其他文本”

当我在警报对话框中显示字符串时,我看到以下内容:

“一些文本rn一些其他文本”

相同的字符串在 TextView 上正确显示,但在 AlertDialog 中却没有。

请建议我应该怎么做。

此致。

编辑 这是我迄今为止尝试过的:

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();

编辑 2: 让我解释一下,我从 Windows 上的 WCF 服务收到 JSON 响应,使用FastJson解析 JSON 解析后从 JSON 收到的文本是

服务器将\r\n 停机进行维护

我们刚刚添加了 \r\n 用于测试目的,但我确信有人会在向 Android 发送数据时使用它们。我尝试使用替换功能进行替换,但没有成功。

4

1 回答 1

0

String#replaceAll在通话中转义反斜杠对我有用

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);

产生:

preprocess text: some text
some other text
postprocess text: some text:some other text
于 2015-10-21T14:33:22.457 回答