w3resource

C#: Remove all vowels from a given string.

C# Sharp Basic: Exercise-83 with Solution

Write a C# Sharp program to remove all vowels from a given string.

Sample Solution:

C# Sharp Code:

using System;
using System.Text.RegularExpressions;

namespace exercises
{
    class Program
    {
        static void Main(string[] args)
        {
            // Declaring a string variable
            string text;

            // Testing the function test with different input strings

            // String containing only letters (Python)
            text = "Python";
            Console.WriteLine("Orginal string: " + text);
            Console.WriteLine("After removing all the vowels from the said string: " + test(text));

            // String containing letters and a space (C Sharp)
            text = "C Sharp";
            Console.WriteLine("\nOrginal string: " + text);
            Console.WriteLine("After removing all the vowels from the said string: " + test(text));

            // String containing only letters (JavaScript)
            text = "JavaScript";
            Console.WriteLine("\nOrginal string: " + text);
            Console.WriteLine("After removing all the vowels from the said string: " + test(text));
        }

        // Method to remove all vowels from a string using Regex
        public static string test(string text)
        {
            // Using Regex.Replace to remove vowels (lowercase and uppercase) from the input string
            return new Regex(@"[aeiouAEIOU]").Replace(text, "");
        }
    }
}

Sample Output:

Orginal string: Python
After removing all the vowels from the said string: Pythn

Orginal string: C Sharp
After removing all the vowels from the said string: C Shrp

Orginal string: JavaScript
After removing all the vowels from the said string: JvScrpt

Flowchart:

Flowchart: C# Sharp Exercises - Remove all vowels from a given string.

C# Sharp Code Editor:

Previous: Write a C# Sharp program to remove all characters which are non-letters from a given string.
Next: Write a C# Sharp program to get the index number of all lower case letters in a given string.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/csharp-exercises/basic/csharp-basic-exercise-83.php