javascript - 在字符串的特定位置添加换行符
问题描述
我怀疑如何在 js 字符串中添加换行符。以下是代码:
{
"id": 7,
"last": 1,
"name": "Customer received Email to change the password/Received. And code that customer hasn’t requested"
},
我想在password/Received
. 我想要所需的输出为
Customer received Email to change the password/Received.
And code that customer hasn’t requested
解决方案
如果要添加换行符并且无法修改文本的来源,则可以执行以下操作:
str = "Customer received Email to change the password/Received. And code that customer hasn’t requested";
str.replace("password/Received. ","password/Received.\n");
如果要以 HTML 格式输出,请替换\n
为。<br/>
推荐阅读
- vb.net - 使用 PDFBox 1.8.9 和 VB Net 突出显示 PDF 中的单词
- c - 如何将结构从 Mac 上的 x86-64 程序集传递给 C 函数(NASM)
- r - 根据列值对行进行分组并在 R 中保留具有最小值的行
- laravel - Laravel 如果相关集合删除父级
- elixir - 对订阅应用过滤器
- c# - 如何在不知道 ID 号的情况下从数据库中检索数据?
- amazon-web-services - 尝试从 AWS beanstalk 配置文件中获取详细信息
- python - 我在 python 中的 telnet 程序与 ip/port 连接太慢
- processing-efficiency - 以 1 或 2 递增:循环速度
- javascript - Firestore:如何更新作为文档参考的文档字段?