Program to Remove all Vowels From String

Program to Remove all Vowels From String

  • Write a program to Remove all Vowels From String in C
  • Write a program to Remove all Vowels From String in C++
  • Write a program to Remove all Vowels From String in Python
  • Write a program to Remove all Vowels From String in PHP
  • Write a program to Remove all Vowels From String in Java
  • Write a program to Remove all Vowels From String in Java Script
  • Write a program to Remove all Vowels From String in C#

Explanation:

The procedure is iterating through the string, examining each character, and eliminating it if it is a vowel (either lowercase or capital). This eliminates all vowels from the string.

Algorithm:

  1. Start with an empty result string.
  2. Loop through each character of the input string.
  3. If the character is not a vowel, add it to the result string.
  4. Return the final string after the loop finishes.

Program to Remove all Vowels From String

#include <stdio.h>
#include <string.h>

void removeVowels(char *str) {
    int i = 0, j = 0;
    while (str[i]) {
        char ch = str[i];
        if (ch != 'a' && ch != 'e' && ch != 'i' && ch != 'o' && ch != 'u' &&
            ch != 'A' && ch != 'E' && ch != 'I' && ch != 'O' && ch != 'U') {
            str[j++] = ch;
        }
        i++;
    }
    str[j] = '\0';
}

int main() {
    char str[100];
    
    // Input string
    printf("Enter a string: ");
    fgets(str, sizeof(str), stdin);
    str[strcspn(str, "\n")] = '\0';  // Remove newline character
    
    // Remove vowels
    removeVowels(str);
    
    printf("String after removing vowels: %s\n", str);
    return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

void removeVowels(std::string &str) {
    str.erase(remove_if(str.begin(), str.end(), [](char ch) {
        ch = tolower(ch);
        return ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u';
    }), str.end());
}

int main() {
    std::string str;
    
    // Input string
    std::cout << "Enter a string: ";
    std::getline(std::cin, str);
    
    // Remove vowels
    removeVowels(str);
    
    std::cout << "String after removing vowels: " << str << std::endl;
    return 0;
}

str1 = input("Enter a string: ")

# Remove vowels
result = ''.join([ch for ch in str1 if ch.lower() not in 'aeiou'])

# Output result
print(f"String after removing vowels: {result}")

<?php
// Input string
echo "Enter a string: ";
$str = trim(fgets(STDIN));

// Remove vowels
$result = preg_replace("/[aeiouAEIOU]/", "", $str);

// Output result
echo "String after removing vowels: $result\n";
?>

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        
        // Input string
        System.out.print("Enter a string: ");
        String str = scanner.nextLine();
        
        // Remove vowels
        String result = str.replaceAll("(?i)[aeiou]", "");
        
        // Output result
        System.out.println("String after removing vowels: " + result);
    }
}

let str = prompt("Enter a string: ");

// Remove vowels
let result = str.replace(/[aeiouAEIOU]/g, "");

// Output result
console.log("String after removing vowels: " + result);

using System;
using System.Linq;

class Program {
    static void Main() {
        // Input string
        Console.Write("Enter a string: ");
        string str = Console.ReadLine();
        
        // Remove vowels
        string result = new string(str.Where(ch => !"aeiouAEIOU".Contains(ch)).ToArray());
        
        // Output result
        Console.WriteLine("String after removing vowels: " + result);
    }
}

List of All Programs