### Select Articles

Remove vowels from a string and return the string with consonants

In a town, houses are marked with English alphabets. Committee in the town wants to renovate the houses. They decided to renovate only houses named with vowels. Committee has given the list to members and asks them to identify the houses which are not renovated. Write an algorithm to help the committee members to find houses which are not renovated.

Input: Input to the function contains only one argument.

House: A string representing the sequence of house markings.

Output: return a string that represents the houses which were not renovated.

The logic to be used:

The logic behind this question is simple. It is to remove the vowels in the given string and display the input string without vowels (i.e with only consonants).

Algorithm to remove vowels from string

Get the input as a string

Define or initialize a string containing the vowels i.e., a, e,i, o, u.

Traverse through the input string, if the vowel is encountered, it should be removed from the string.

Another way is to initialize another string and copy each non-vowel character to this string from the input string.

Display the final result string.

Program to remove vowels from a string

Asked in recruitment drive of companies like Wipro

C

#include

int check_vowel(char);

int main()

{

char s[100], t[100];

int c, d = 0;

gets(s);

for(c = 0; s[c] != ‘\0’; c++)

{

if(check_vowel(s[c]) == 0)

{

t[d] = s[c];

d++;

}

}

t[d] = ‘\0’;

strcpy(s, t);

printf(“%s\n”, s);

return 0;

}

int check_vowel(char ch)

{

if (ch == ‘a’ || ch == ‘A’ || ch == ‘e’ || ch == ‘E’ || ch == ‘i’ || ch == ‘I’ || ch ==’o’ || ch==’O’ || ch == ‘u’ || ch == ‘U’)

return 1;

else

return 0;

}

C++

#include

#include

#include

#include

using namespace std;

int check_vowel(char check_character)              // To check the vowels

{

if (check_character == 'a' || check_character =='A' ||

check_character == 'e' || check_character =='E' || check_character == 'i' ||

check_character =='I' || check_character == 'o' || check_character =='O' || check_character == 'u' || check_character =='U')

return 1;

else

return 0;

}

int main()

{

string input_string;

int j=0;

cout<<"Enter the String:";                 // Getting Input String

cin>>input_string;

int string_length = 0;

while (input_string[string_length])

string_length++; // Calculating the size of the string

char result_string[string_length];

for(int i=0; i< string>

{

int temp = check_vowel(input_string[i]);

if (temp == 0) //if not a vowel, it will be attached to the new string

{

result_string[j] += input_string[i];

j++;

}

}

cout<

return 0;

}

JAVA

import java.util.Scanner;

public class Main

{

public static void main(String[] args)

{

System.out.println(“Enter the string…”);

Scanner sc = new Scanner(System.in);

String input = sc.nextLine();

String result = input.replaceAll(“[AEIOUaeiou]”, “”);                 // Replacing the vowels with “”

System.out.println(result);

}

}

PYTHON 3

s = input(“Enter any string to remove all vowels from it: “)

vowels = (‘aeiou’)

s = s.lower()

for x in s:

if x in vowels:

s = s.replace(x, “”)   // Replacing the vowels with ‘’

print(s)

Output

Input- qwertyuiop Output- qwrtyp