Replacing characters in C# (ascii)

前端 未结 7 925
挽巷
挽巷 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:12

    Why are you making things complicated?

    line = line.Replace('à', 'a');
    

    Update:

    The docs for File.ReadAllText say:

    This method attempts to automatically detect the encoding of a file based on the presence of byte order marks. Encoding formats UTF-8 and UTF-32 (both big-endian and little-endian) can be detected.

    Use the ReadAllText(String, Encoding) method overload when reading files that might contain imported text, because unrecognized characters may not be read correctly.

    What encoding is C:/Joiner.csv in? Maybe you should use the other overload for File.ReadAllText where you specify the input encoding yourself?

提交回复
热议问题