Replacing characters in C# (ascii)

前端 未结 7 971
挽巷
挽巷 2020-12-05 08:26

I got a file with characters like these: à, è, ì, ò, ù - À. What i need to do is replace those characters with normal characters eg: à = a, è = e and so on..... This is my c

7条回答
  •  长情又很酷
    2020-12-05 09:23

    Doing it the easy way. The code below will replace all special characters to ASCII characters in just 2 lines of code. It gives you the same result as Julien Roncaglia's solution.

    byte[] bytes = System.Text.Encoding.GetEncoding("Cyrillic").GetBytes(inputText);
    string outputText = System.Text.Encoding.ASCII.GetString(bytes);
    

提交回复
热议问题