Question #283253

Write a program to delete all vowels present in a string in c#


Expert's answer

This code

  1. Reads a string from console input
  2. Creates regular expression (Regex) object with vowels pattern and case ignoring
  3. Writes string where vowels replaced with empty string to console output
using System;
using System.Text.RegularExpressions;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var vowelRegex = new Regex(@"[a|e|i|o|u]", RegexOptions.IgnoreCase | RegexOptions.Compiled);
            Console.WriteLine(vowelRegex.Replace(s, ""));
        }
    }
}
LATEST TUTORIALS
APPROVED BY CLIENTS