Joh*_*ohn 1 google-docs google-docs-api google-apps-script
Google 文档不允许像其他文本编辑器一样使用搜索和替换来删除多余的空格。任何人都可以帮助使用 Google Apps 脚本搜索文档以查找两个或多个空格的所有实例并将它们替换为单个空格吗?
小智 5
可以使用以下单行函数完成这样的替换:
function spaces() {
DocumentApp.getActiveDocument().getBody().replaceText(" +", " ");
}
Run Code Online (Sandbox Code Playgroud)
参考:replaceText 方法。