How to count vowels and Consonants given string



Hi All,

How to get Vowels and Consonants in string.

Please help me.



Try this for Vowels, figure out your way for Consonents

int VowelCount = strAlphabets.Count(Function(c) "aeiou".Contains([Char].ToLower(c)))


As a non-programmer, I would really appreciate a breakdown of each part of this function :confused:



A way using regular expressions:

Int32 vowelCount = Regex.Matches(givenString, "[aeiou]", RegexOptions.IgnoreCase).Count
Int32 consonantCount = Regex.Matches(givenString, "[a-z-[aeiou]]", RegexOptions.IgnoreCase).Count

This is fairly self-explanatory, but I will clarify that [a-z-[aeiou]] means “one character in the range a-z, but not in the set aeiou”. Equivalently, [b-z-[eiou]] will do or [bcdfghj-np-tv-z], but that would be rather less clear.

You can achieve the same result by first getting the (array of) Matches using the Matches activity (from the Workflow Manager package) and then getting the Count.


Hi Steven,

Did it with your suggestions :smiley:
Main.xaml (14.2 KB)


This is vvaidya’s expression in words:

In strAlphabets, count the number of characters for which this predicate holds: the string “aeiou” contains the lowercase version of the current character.

This Count method is probably already familiar, as it can also be used without arguments to simply get the number of elements in array-type variables. It can also be passed a Function argument, which will be applied to each element of the array and must return a Boolean value. In that case, Count returns the number of resulting True values.