Reputation: 31
Google Documents don't allow extra spaces to be removed using search and replace like other text editors. Can anyone help with a Google Apps Script that searches a Document for all instances of two or more spaces and replaces them with single spaces?
Upvotes: 2
Views: 3983
Reputation: 103
I got TypeError: Cannot read properties of null (reading 'getBody')
Upvotes: 0
Reputation:
Such a replacement can be done with the following one-line function:
function spaces() {
DocumentApp.getActiveDocument().getBody().replaceText(" +", " ");
}
Reference: replaceText method.
Upvotes: 6