public static void main (String[] args) {
System.out.println("Simple Java Word Count Program");
String str1 = "Today is Holdiay Day";
String[] wordArray = str1.trim().split("s+");
int wordCount = wordArray.length;
System.out.println("Word count is = " + wordCount);
}
function countWords(str) {
return str.trim().split(/s+/).length;
}
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);
function WordCount(str) {
return str.split(" ").length;
}
console.log(WordCount("hello world"));
str.match(/w+/g).length;
def get_len(text):
'''function to get the count of words in string'''
import re
# using regex (findall())
# to count words in string
res = len(re.findall(r'w+', text))
return res