Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to count number of words in a string

 String name = "Carmen is a fantastic play"; //arbitrary sentence
        
        int numWords = (name.split("s+")).length; //split string based on whitespace
                                                //split returns array - find legth of array
        
        System.out.println(numWords);
Source by www.java67.com #
 
PREVIOUS NEXT
Tagged: #count #number #words #string
ADD COMMENT
Topic
Name
3+3 =