Created
July 3, 2020 13:15
-
-
Save chendy/5f28e8455319427af86a8665a58a32c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printWordsBetweenAngleBrackets(){ | |
let doc = DocumentApp.getActiveDocument(); | |
let body = doc.getBody(); | |
let text = body.editAsText(); | |
// all the documents text as a long string AFAIK | |
let textString = text.getText(); | |
let startToken = false; | |
let tokens = []; | |
let token = ""; | |
for (let i=0; i<textString.length;i++){ | |
let c = textString[i]; | |
if (c == "<"){ | |
//Logger.log(i, "<"); | |
startToken = true; | |
continue; | |
} | |
if (c == ">"){ | |
tokens.push(token); | |
token = ""; | |
startToken = false; | |
continue; | |
} | |
if (startToken){ | |
token += c; | |
} | |
} | |
tokens = new Set(tokens); | |
tokens = Array.from(tokens) | |
//Logger.log(tokens); | |
tokens = tokens.sort(); | |
Logger.log(tokens); | |
//Append a paragraph and a page break to the document body section directly. | |
//body.appendParagraph("A paragraph."); | |
//body.appendPageBreak(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment