首页 > 解决方案 > 在字符串的特定位置添加换行符

问题描述

我怀疑如何在 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

标签: javascriptjquery

解决方案


如果要添加换行符并且无法修改文本的来源,则可以执行以下操作:

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/>


推荐阅读