---
title: "How do you count a number of vowels and consonants in a given string?"  
description: "How do you count a number of vowels and consonants in a given string?"  
author: "Mukul Goenka"  
published: 2021-11-10  
updated: 2021-11-10  
canonical: https://www.mindstick.com/forum/156816/how-do-you-count-a-number-of-vowels-and-consonants-in-a-given-string  
category: "c#"  
tags: ["c#", ".net"]  
reading_time: 2 minutes  

---

# How do you count a number of vowels and consonants in a given string?

How do you [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) a number of vowels and consonants in a given [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)?

## Replies

### Reply by Ravi Vishwakarma

## Program

```
using System;
class HelloWorld {
  static void Main() {
    HelloWorld hw = new HelloWorld();
        hw.CountVovelAndConsonant('I know you it ');
  }
  void CountVovelAndConsonant(string str){
      int noVowel=0, noConsonant=0;
    char[] charArray = str.ToCharArray();
      foreach(char ch in charArray){
          if (ch == ' ')
            continue;
          else if(IsVowel(ch))
            noVovel++;
          else
            noConsonant++;
      }
      Console.WriteLine('No of Vowel {0} and No of Consonant {1}',noVowel, noConsonant);
  }
  bool IsVowel(char ch){
      switch(Char.ToLower(ch)){
          case 'a':
          case 'e':
          case 'i':
          case 'o':
          case 'u':
            return true;
        default:
            return false;
      }
  }
}
```

## Output

## No of Vowel 5 and No of Consonant 5


---

Original Source: https://www.mindstick.com/forum/156816/how-do-you-count-a-number-of-vowels-and-consonants-in-a-given-string

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
