我从Windows应用程序收到一个字符串,字符串是这样的:
“一些文字\ r \ n其他文字”
当我在警告对话框中显示字符串时,我看到以下内容:
“某些文字 其他一些文字”
相同的字符串在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用于测试目的,但我确信有人会在向Android发送数据时使用它们。 我尝试使用替换功能替换,但没有成功。
答案 0 :(得分: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