Answers for "str count number of words in a string"

1

Count number of words in a String

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);
}
Posted by: Guest on August-14-2021
0

count words in a string

function WordCount(str) { 
  return str.split(" ").length;
}

console.log(WordCount("hello world"));
Posted by: Guest on April-07-2022

Code answers related to "str count number of words in a string"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language