Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

google docs api word count

function countWords() {
    var s = DocumentApp.getActiveDocument().getBody().getText();
    //this function kept returning "1" when the doc was blank 
    //so this is how I stopped having it return 1.       
    if (s.length === 0) 
        return 0;
    //A simple 
 replacement didn't work, neither did s not sure why
    s = s.replace(/
|
|
/g, " ");
    //In cases where you have "...last word.First word..." 
    //it doesn't count the two words around the period.
    //so I replace all punctuation with a space
    var punctuationless = s.replace(/[.,/#!$%^&*;:{}=-_`~()"?“”]/g," ");
    //Finally, trim it down to single spaces (not sure this even matters)
    var finalString = punctuationless.replace(/s{2,}/g," ");
    //Actually count it
    var count = finalString.trim().split(/s+/).length; 
    return count;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: why my style not come to angular 11 
Javascript :: how many characters can fit in 1 line of div 
Javascript :: change linear bagckgorund by javascript 
Javascript :: nodejs createcipheriv invalid key length 
Javascript :: fixed nodeport 
Javascript :: Ocultar o mostrar elementos HTML con JQuery 
Javascript :: create react app cloudfront invalidation 
Javascript :: react native multiple touchableopacity 
Javascript :: JavaScript Operator Precedence Values 
Javascript :: how to get last value knex in postgresql 
Javascript :: time calculate midpoint between two dates js 
Javascript :: Ambobulamblation 
Javascript :: hj hjkl jkl 
Javascript :: traduire text with api translate google in react 
Javascript :: website to word array 
Javascript :: strpad jquery 
Javascript :: how to press enter key automatically using javascript 
Javascript :: javaScipt diference != and !== 
Javascript :: hooks in bdd 
Javascript :: Node.js passing parameters to client via express render 
Javascript :: create an all day event by drag and drop 
Javascript :: react userefrence example 
Javascript :: SyntaxError 
Javascript :: elasticsearch performance 
Javascript :: avoid-browser-pop-up-blockers 
Javascript :: movie-trailer usage 
Javascript :: how to check if an image exists in js from cross origin 
Javascript :: javascript Ecrire une fonction afficherTable2() qui affiche la table de multiplication de 2 dans le contenu d’un élément p. 
Javascript :: how to use variable key as dictionary key in javascript 
Javascript :: javascript client side email 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =