Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何删除HTML中的额外空间或新行_Javascript_Html - Fatal编程技术网

Javascript 如何删除HTML中的额外空间或新行

Javascript 如何删除HTML中的额外空间或新行,javascript,html,Javascript,Html,当我调用API时,我收到如下响应 { "statusCode": 200, "message": null, "responseBody": { "subject": "Task2", "emailContent": "", "emailContentTrail": "Hi ,\r\nRepl

当我调用API时,我收到如下响应

{
  "statusCode": 200,
  "message": null,
  "responseBody": {
    "subject": "Task2",
    "emailContent": "",
    "emailContentTrail": "Hi ,\r\nReplying\r\nFrom Outlook\r\n\r\nIn multiple\r\nLines\r\n\r\nthanks you,\r\nSam \r\n________________________________\r\nFrom: Workflow,\r\nSent: Monday, April 5, 2021 12:01 PM\r\nTo: Workflow,\r\nCc: Sam \r\nSubject:Task2\r\n\r\nCAUTION: EXTERNAL EMAIL. Please do not reply, forward, or open links/attachments unless you recognize the sender.\r\n\r\nHi ,\r\n\r\nMultiple Line\r\n\r\nMessage Checking\r\n\r\n\r\nMessage\r\n\r\n\r\nThank you,\r\n\r\nSam \r\n\r\n\r\n________________________________\r\nTry to see whether extra space can be removed using css or regex pattern\r\n\r\n\r\nDisclaimer: The information contained in this e-mail and any accompanying documents may contain information that is confidential or otherwise protected from disclosure. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message, including any attachments. Any dissemination, distribution or other use of the contents of this message by anyone other than the intended recipient is strictly prohibited. Any comments or statements made are not necessarily those of Xceedance. All messages sent to and from this e-mail address may be monitored as permitted by applicable law and regulations to ensure compliance with our internal policies and to protect our business. E-mails are not secure and cannot be guaranteed to be error free as they can be intercepted, amended, lost or destroyed, or contain viruses. You are deemed to have accepted these risks if you communicate with us by e-mail.\r\n",
    "attachments": []
  },
  "page": null,
  "links": null,
  "error": false
}
我必须在文本区域中显示“emailContentTrail”数据。 但我想删除现有的附加新行。我该怎么做呢。 目前数据如下所示

正如你所看到的,两个文本之间有很多空白。我想删除那个空间。
如何操作。

尝试将
\r\n\r\n
替换为
\r\n
,您可以使用以下正则表达式:

emailContentTrail.replaceAll("(\r?\n){2,}", "\r\n");

您可以使用以下代码删除字符串中的所有新行:

var originalText=“这是一个测试文本,下一行\n将被删除!”
var removedNewLinesText=originalText.replace(/(\r\n |\n |\r)/gm,“”);
console.log(原始文本);

console.log(removedNewLinesText)我想保留格式,但如果有两个\n\n,我只想删除