如何在 Google Apps 脚本中的每个点后添加一个新行

How to add a new Line after every dot in Google Apps Script

基于 Google Doc 文档,我正在创建一个 Google Apps 脚本,它将 Google Doc 文档的表格中的可用文本插入 Google Sheet。由于有时文本很长,因此 Google Sheet 中插入的文本看起来不太好。也使用 sheet.autoResizeColumns(3,sheet.getLastColumn()) 但由于文本的长度,它看起来不太好。

所以我想在每个点后的字符串文本中添加一个新行。我尝试了 testText = testText.replace('.','\n') 但这只是用新行替换了第一个点并且还删除了点。我想要的是在整个字符串的点之后有一个新行,而不是删除点。例如:

var testText = 'This approach is very good. Thank you very much for your Attention. We will send you messages.'

想要的文字:

var wantedText = 'This approach is very good.
                  Thank you very much for your Attention.
                  We will send you messages.'

如何在 Google Apps 脚本中执行此操作?

参见 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals:使用反引号(重音符号)字符代替双引号或单引号

function literals(){
  var wantedText = `This approach is very good.
Thank you very much for your Attention.
We will send you messages.`
  Logger.log(wantedText)
}

如果文本来自单元格,请使用:

function breakLine(){
  var testText = 'This approach is very good. Thank you very much for your Attention. We will send you messages.'
  var wantedText = testText.replace(/(\.)/gm,"\.\n");
  Logger.log(wantedText)
}

如有必要,在点

后添加space
var wantedText = testText.replace(/(\. )/gm,"\.\n");