Description
To remove vowels from string store only consonant in a character array. The program will take string as a user input and give output a string having no any vowels.
C/C++
/* C Program to remove vowels from a String*/ //Save it as RemoveVowel.c #include<stdio.h> int checkVowel(char); int main(){ int i, count=0; char str[50], newStr[50]; printf("Enter a string : "); scanf("%s",str); /*In complete string checking if character is consonent, store it in a new character array*/ for(i=0;str[i]!='\0';i++){ if(checkVowel(str[i]) == 0){ newStr[count] = str[i]; count++; } } //Assigning null at the end of new character array newStr[count] = '\0'; //Copying the new character array into a original character array strcpy(str, newStr); printf("The string after removal of vowel : %s",str); return 0; } //Function to check vowels in string int checkVowel(char val){ if(val=='a' || val=='A' || val=='e' || val=='E' || val=='i' || val=='I' || val=='o' || val=='O' || val=='u' || val=='U'){ return 1; }else{ return 0; } }
Input: Enter a string : sachin Output: The string after removal of vowel : schn
Java
/* Java Program to remove vowels from a String*/ //Save it as RemoveVowel.java import java.io.*; import java.util.Scanner; public class RemoveVowel { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("Enter a string : "); String str = scanner.nextLine(); String s1 = str.replaceAll("[AEIOUaeiou]" , ""); System.out.println("The string after removal of vowel : "+s1); } }
Input: Enter a string : sachin Output: The string after removal of vowel : schn
Related Programs
1) Program to Check Whether a Character is a Vowel or Not2) Program to Find ASCII value of a character
3) Program to check entered character is vowel or consonants
4) Program to count Vowels, Consonants, Digits and Whitespaces
5) Program to Replace Spaces With Dots
6) Program to find maximum number of 1s in a substring of a String
7) Count Number of Words in a String
8) Find Occurrence Of Each Word In a Sentence
9) Print All Unique Words Of A String
10) Program To Print Unique Word Of A String Using Set