Count vowels in a word

drJava

I need to find count of the vowels in a word. However, when I compare the letters in the word whether they are vowel or not,

For example, what I do is like the one below,

if( word[i] == 'a' || word[i] == 'e' || word[i] == 'i' || word[i] == 'u' ...... ) //the rest is omitted

the if statement gets too long. Is there a way to compare them with a regex or regex-like comparison and give me the number of vowel occurrences in a string?

rock321987

If you want to find all vowels

String line = "Ahis order was placed for QT3000! OK?";
String pattern = "(?i)[aeiou]";

Pattern r = Pattern.compile(pattern);

Matcher m = r.matcher(line);

while (m.find()) {
   System.out.println(m.group(0) );
}

If you want to find number of times they occur you can use replace like

String line = "Ahis order was placed for QT3000! OK?";
String pattern = "(?i)[aeiou]";
System.out.println(line.replaceAll(pattern, "").length());

NOTE :- (?i) is inline modifier which indicates whatever pattern follows it will be case insensitive

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Count specific vowels in a sentence

From Dev

counting the number of vowels in a word in a string

From Dev

Remove vowels except if it the starting of the word

From Dev

python vowels counter in each word

From Dev

Removing ending vowels from a word

From Dev

Count the number of vowels in an array in PHP

From Dev

Printing the vowels and the vowel count in a string

From Dev

Count the number of vowels in an array in PHP

From Dev

Replace vowels in string with word "oodle" without replacing the vowels in "oodle"

From Dev

method evaluating a word with vowels in alphabetical order

From Dev

Finding out if half the letters in a word are vowels

From Dev

Is there a better way to check for vowels in the first position of a word?

From Dev

How to add Hebrew vowels in Word 2010

From Dev

Program to print a word with most number of vowels

From Dev

How to extract consonant / vowels groups from a word ?

From Dev

Eliminating Vowels in order from a word C++

From Dev

Lua - Idea on lua for split a word into vowels and consonants

From Dev

Selecting the first consonant in a word (following a number of vowels)

From Dev

Program to count evens odds vowels and consonants in a string

From Dev

C++ vector and string, count vowels

From Dev

Unable to count vowels using java multithreading

From Dev

Count the number of vowels and print them in a manner that string having more vowels come first

From Dev

Perl word disenvoweling: removing all vowels except the first and last

From Dev

Q: Using Grep to find a word that contains each of the vowels in the correct order

From Dev

How to count vowels in a String including which have accent marks?

From Dev

Count the vowels in a string including Y if its followed by a consonant

From Dev

is there a more efficient way to count how many vowels in a string?

From Dev

Scala Map Word Count?

From Dev

Word count in AngularJS

Related Related

  1. 1

    Count specific vowels in a sentence

  2. 2

    counting the number of vowels in a word in a string

  3. 3

    Remove vowels except if it the starting of the word

  4. 4

    python vowels counter in each word

  5. 5

    Removing ending vowels from a word

  6. 6

    Count the number of vowels in an array in PHP

  7. 7

    Printing the vowels and the vowel count in a string

  8. 8

    Count the number of vowels in an array in PHP

  9. 9

    Replace vowels in string with word "oodle" without replacing the vowels in "oodle"

  10. 10

    method evaluating a word with vowels in alphabetical order

  11. 11

    Finding out if half the letters in a word are vowels

  12. 12

    Is there a better way to check for vowels in the first position of a word?

  13. 13

    How to add Hebrew vowels in Word 2010

  14. 14

    Program to print a word with most number of vowels

  15. 15

    How to extract consonant / vowels groups from a word ?

  16. 16

    Eliminating Vowels in order from a word C++

  17. 17

    Lua - Idea on lua for split a word into vowels and consonants

  18. 18

    Selecting the first consonant in a word (following a number of vowels)

  19. 19

    Program to count evens odds vowels and consonants in a string

  20. 20

    C++ vector and string, count vowels

  21. 21

    Unable to count vowels using java multithreading

  22. 22

    Count the number of vowels and print them in a manner that string having more vowels come first

  23. 23

    Perl word disenvoweling: removing all vowels except the first and last

  24. 24

    Q: Using Grep to find a word that contains each of the vowels in the correct order

  25. 25

    How to count vowels in a String including which have accent marks?

  26. 26

    Count the vowels in a string including Y if its followed by a consonant

  27. 27

    is there a more efficient way to count how many vowels in a string?

  28. 28

    Scala Map Word Count?

  29. 29

    Word count in AngularJS

HotTag

Archive