向输出空间或新行添加新行或空格

Add a new row or spaces to output space or a new row

本文关键字:新行 空格 添加 输出 空间      更新时间:2023-09-26

我需要帮助在脚本中添加空间或新行。它看起来像这样:

function myFunction() {
 var firstThread = GmailApp.getInboxThreads(0,1)[0];
 var message = firstThread.getMessages()[0];
 var sender = message.getFrom();
 var body = "This email is sent from:" + " " + sender + message.getPlainBody();
 var subject = message.getSubject();
 var attachment = message.getAttachments();
 GmailApp.sendEmail("user.name@aruba.com", subject, body, {attachments: attachment});
}

我需要在"This email is sent from:" + " " + sender "

下面的新行添加"message.getPlainBody();"

现在都在Email的同一行。是否有类似的东西像html标签<br> ?

您可以在字符串中插入换行/换行字符以开始新的行。注意'n,它实际上算作1个字符('开始一个转义序列)

var body = "This email is sent from:'n" + sender + "'n'n" + message.getPlainBody();

试着添加'n:

var body = "This email is sent from: " + sender + "'n" + message.getPlainBody();