Program to remove vowels from a String
Given a string, remove the vowels from the string and print the string without vowels.
Examples:
Input : welcome to geeksforgeeks Output : wlcm t gksfrgks Input : what is your name ? Output : wht s yr nm ?
A loop is designed that goes through a list composed of the characters of that string, removes the vowels and then joins them.
C++
// C++ program to remove vowels from a String #include <bits/stdc++.h> using namespace std; string remVowel(string str) { vector<char> vowels = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'}; for (int i = 0; i < str.length(); i++) { if (find(vowels.begin(), vowels.end(), str[i]) != vowels.end()) { str = str.replace(i, 1, ""); i -= 2; } } return str; } // Driver Code int main() { string str = "GeeeksforGeeks - A Computer" " Science Portal for Geeks"; cout << remVowel(str) << endl; return 0; } // This code is contributed by // sanjeev2552 |
chevron_right
filter_none
Java
// Java program to remove vowels from a String import java.util.Arrays; import java.util.List; class Test { static String remVowel(String str) { Character vowels[] = {'a', 'e', 'i', 'o', 'u','A','E','I','O','U'}; List<Character> al = Arrays.asList(vowels); StringBuffer sb = new StringBuffer(str); for (int i = 0; i < sb.length(); i++) { if(al.contains(sb.charAt(i))){ sb.replace(i, i+1, "") ; i--; } } return sb.toString(); } // Driver method to test the above function public static void main(String[] args) { String str = "GeeeksforGeeks - A Computer Science Portal for Geeks"; System.out.println(remVowel(str)); } } |
chevron_right
filter_none
Python
# Python program to remove vowels from a string # Function to remove vowels def rem_vowel(string): vowels = ('a', 'e', 'i', 'o', 'u') for x in string.lower(): if x in vowels: string = string.replace(x, "") # Print string without vowels print(string) # Driver program string = "GeeksforGeeks - A Computer Science Portal for Geeks"rem_vowel(string) |
chevron_right
filter_none
C#
// C# program to remove vowels from a String using System; using System.Text; using System.Linq; using System.Collections.Generic; public class Test { static String remVowel(String str) { char []vowels = {'a', 'e', 'i', 'o', 'u','A','E','I','O','U'}; List<char> al = vowels.OfType<char>().ToList();; StringBuilder sb = new StringBuilder(str); for (int i = 0; i < sb.Length; i++) { if(al.Contains(sb[i])){ sb.Replace(sb[i].ToString(), "") ; i--; } } return sb.ToString(); } // Driver method to test the above function public static void Main() { String str = "GeeeksforGeeks - A Computer Science Portal for Geeks"; Console.Write(remVowel(str)); } } //This code is contributed by Rajput-Ji |
chevron_right
filter_none
Output:
GksfrGks - Cmptr Scnc Prtl fr Gks
We can improve the above solution by using Regular Expressions.
Java
// Java program to remove vowels from a String import java.util.Arrays; import java.util.List; class GFG { static String remVowel(String str) { return str.replaceAll("[aeiouAEIOU]", ""); } // Driver Code public static void main(String[] args) { String str = "GeeeksforGeeks - A Computer Science Portal for Geeks"; System.out.println(remVowel(str)); } } |
chevron_right
filter_none
C#
// C# program to remove vowels from a String using System; using System.Text.RegularExpressions; class GFG { static String remVowel(String str) { str = Regex.Replace(str, "[aeiouAEIOU]", ""); return str; } // Driver code public static void Main() { String str = "GeeeksforGeeks - A Computer Science Portal for Geeks"; Console.WriteLine(remVowel(str)); } } //This code is contributed by 29AjayKumar |
chevron_right
filter_none
Output:
GksfrGks - Cmptr Scnc Prtl fr Gks
This article is contributed by Pramod Kumar. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Recommended Posts:
- Remove consecutive vowels from string
- Program to duplicate Vowels in String
- Program to count vowels in a string (Iterative and Recursive)
- C program to count number of vowels and consonants in a String
- Python program to count number of vowels using sets in given string
- Program to count vowels, consonant, digits and special characters in string.
- C++ Program to remove spaces from a string
- Program to remove consonants from a String
- Check if a string can be converted to another string by replacing vowels and consonants
- First X vowels from a string
- Reverse vowels in a given string
- Modify the string such that it contains all vowels at least once
- Permutations of string such that no two vowels are adjacent
- Count the pairs of vowels in the given string
- Replace all consonants with nearest vowels in a string


