check how many of a word is in a string

function countOccurences(str,word)  
{ 
    // split the string by spaces in a 
    String a[] = str.split(","); 
  
    // search for pattern in a 
    int count = 0; 
    for (int i = 0; i < a.length; i++)  
    { 
    // if match found increase count 
    if (word.equals(a[i])) 
        count++; 
    } 
  
    return count; 
} 

4
10
Rnd 95 points

                                     public static int count(String word) {
    if (word == null || word.isEmpty()) {
      return 0;
    }

    int wordCount = 0;

    boolean isWord = false;
    int endOfLine = word.length() - 1;
    char[] characters = word.toCharArray();

    for (int i = 0; i &lt; characters.length; i++) {

      // if the char is a letter, word = true.
      if (Character.isLetter(characters[i]) &amp;&amp; i != endOfLine) {
        isWord = true;

        // if char isn't a letter and there have been letters before,
        // counter goes up.
      } else if (!Character.isLetter(characters[i]) &amp;&amp; isWord) {
        wordCount++;
        isWord = false;

        // last word of String; if it doesn't end with a non letter, it
        // wouldn't count without this.
      } else if (Character.isLetter(characters[i]) &amp;&amp; i == endOfLine) {
        wordCount++;
      }
    }

    return wordCount;
  }

4 (10 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to find how many words there are in a string java check how many of one specific letter in word java check how many specific letter in word Counting number of wordds and charcter in a string java string count word in a string What is the count of occurrences of the word count word in string count how many words in a string c create a function to count the words in a string find occurrence of word in string java count words in a senetence cpp count word occurrences java find occurance of how to count words in string . Java program to find the number of words in String ? find the numbe of words in a string c program how many word count the number of words in a string in java Write a program to enter a string and count total number of word The/the in the given string. string method to count number of words count word occurance in string eperated by new line char number of words in a string occurrence of word in string in java word count in java count_words.c how to find occurrence of words in string in java how to find occurrence of words in string count occurrences of word in string c++ no of words in a string count words into string c++ count the number of occurrences of a word in string cpphow many times a word in string count number of words gfg how to check if all the chars in word are letters find number of words in string get number of wordes from string how do you find as many instances of a word in a string using puthpn3 code given a string, count how many occurrences of each word javascript given a string, count how many occurrences of each word count words in a string no numbers count string sentence read a string and count allin stance of agiven word count occurrences of all words in string c++ count occurrences of all words in string Count words in a string how to find out how many times a word appear in a string ? s - count the number of words in the set that start with s word occurrence in java count numbers in given text how to count words in phrase in java java Program to find bo of occurances of words find number of words in a string word count engine gfg Write PHP statement(s) to display the following: a. To count the number of words the string assigned to the variable $AuthorDetails contains. count the number of words in an array count words in java string find occurrences in string int findwords(int) : to count the total number of words in the string using Recursive technique and store in &lsquo;w&rsquo; and return. count nb word in string count nb word in string* Given a document, implement an algorithm to count the number of word occurrences. how to count how many word in a string program to count word length count occurrences of word in string java find number of occurrences in string code to count all the words of each length in text how to count all word occurrence in java how to count word occurrence in java counting how many times a word is passed the parameters java Write a function to print and count all words having length 4. Count no occurrences of a word in a string, where word is given by a user. how to count string occurence in a phrase in java return the number of individual words in a string max no of words in given string in python how to count the word in string howMany(String sentence) count number of words in sentence code string occurrence count how to count words in a string and if they are equal print how to count words entered count number of words in a line java counting number of words in a string how many words in sentense programming question javascript count number of words in a string count occurrences of word in sentence in java check how many of a word is in a string count words in sentence exclude number , and ? string count words c check each word and number in a string in c Write a function that returns the number of words in a string. Write a function countWords that returns the number of words in a string.
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source