Write a C# Sharp program to remove all characters which are non-letters from a given string

  • برمجة سي شارب
  • برمجة

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 Output:

Orginal string: Py@th12on
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

الأجوبة

using System;
using System.Text.RegularExpressions;

namespace exercises
{
    class Program
    {
        static void Main(string[] args)
          {
            string text;
            text = "Py@th12on";
            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]", "");
        }
    }
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...