java - 如何将 "\n "替换为新行?

标签 java android string rawstring

我有一个下面提到的 RawString

"Link\">https:\/\/tsad.rs\/2RBWI5E\n\n    By Tom Westbrook\n    sjda, asd 14 (sda) - sad dsad asd lower on\nTuesday, but gains in riskier currencies were capped as traders\nfretted adlaj \nladsadj \n   Available to our procedure.JPY=

only one thing need to fix in this, where i am getting "\n" with space that mentioned below.

\n   By Tom Westbrook
Text after "\n" with space want to show in Next line remove this "\n" but where i am getting only \n like below.
on\nTuesday,
i want to add null String like "". How can i achieve this. i am using like this but not getting proper result.

 sentences[i] = sentences[i].replaceAll("\\n ", "");
 sentences[i] = sentences[i].replaceAll("\\n", "");

最佳答案

您可以在 java 中使用以下代码 fragment 来获得所需的输出。

String str = s.replaceAll("\\\\n", "~")
              .replaceAll("~\\s", System.lineSeparator())
              .replaceAll("~", "");

关于java - 如何将 "\n "替换为新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61200609/

相关文章:

Java 日期格式

java - 在java中运行脚本的有效方法

java - 组合框选项中的文本对齐方式

android - 如何测量可组合物?

python - 为什么 "in"适用于键而不适用于字符串?

javascript - 如何删除 Javascript 字符串中的所有字符?

java - 访问超出整数范围的字符串字符

java - AtomicLong 的 incrementAndGet 方法在内部如何工作?

android - ProgressDialog 和 AlertDialog 导致窗口泄漏

java - 图片上传到服务器的php错误响应= httpclient.execute(httppost);