C# Sharp Exercises: Remove all characters which are non-letters from a given string
C# Sharp Basic: Exercise-82 with Solution
Write a C# Sharp program to remove all characters which are non-letters from a given string.
From Wikipedia,
A letter is a segmental symbol of a phonemic writing system. The inventory of all letters forms the alphabet. Letters broadly correspond to phonemes in the spoken form of the language, although there is rarely a consistent, exact correspondence between letters and phonemes
Sample Solution:
C# Sharp Code:
using System;
using System.Text.RegularExpressions;
namespace exercises
{
class Program
{
static void Main(string[] args)
{
string text;
text = "[email protected]";
Console.WriteLine("Orginal string: "+text);
Console.WriteLine("Remove all characters from the said string which are non-letters: " + test(text));
text = "Python 3.0";
Console.WriteLine("\nOrginal string: " + text);
Console.WriteLine("Remove all characters from the said string which are non-letters: " + test(text));
text = "2^sdfds*^*^jlljdslfnoswje34u230sdfds984";
Console.WriteLine("\nOrginal string: " + text);
Console.WriteLine("Remove all characters from the said string which are non-letters: " + test(text));
}
public static string test(string text)
{
return Regex.Replace(text, @"[^a-zA-Z]", "");
}
}
}
Sample Output:
Orginal string: [email protected] Remove all characters from the said string which are non-letters: Python Orginal string: Python 3.0 Remove all characters from the said string which are non-letters: Python Orginal string: 2^sdfds*^*^jlljdslfnoswje34u230sdfds984 Remove all characters from the said string which are non-letters: sdfdsjlljdslfnoswjeusdfds
Flowchart:
C# Sharp Code Editor:
Improve this sample solution and post your code through Disqus
Previous:Write a C# Sharp program to swap a two digit given number and check whether the given number is greater than its swap value.
Next:Write a C# Sharp program to remove all vowels from a given string.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework