C#: Remove all vowels from a given string.
Remove Vowels from String
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:
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.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics