How to remove all characters from a string except the alphabets in C#

1 Answer

0 votes
using System; 
  
class Test 
{ 
    static string remove_characters_except_alphabets(string s) { 
        for (int i = 0; i < s.Length; i++) { 
            if (s[i] < 'A' || s[i] > 'Z' && s[i] < 'a' || s[i] > 'z') {  
                s = s.Remove(i,1); 
                i--; 
            } 
        } 
          
        return s;
    } 
      
    public static void Main() 
    { 
        string s = "c#, programming//? version@#$ 7.3";
        
        s = remove_characters_except_alphabets(s); 
        
        Console.Write(s); 
        
    }  
}


/*
run:

cprogrammingversion

*/

 



answered Feb 1, 2019 by avibootz
...