Conversion from UTF8 to ASCII

后端 未结 2 417
小鲜肉
小鲜肉 2020-12-14 10:59

I have a text read from a XML file stored in UTF8 encoding. C# reads it perfectly, I checked with the debugger, but when I try to convert it to ASCII to save it in another f

2条回答
  •  失恋的感觉
    2020-12-14 11:37

    Those characters have no mapping in ASCII. Review an ASCII table, like Wikipedia's, to verify this. You might be interested in the Windows 1252 encoding, or "extended ASCII", as it's sometimes called, which has code points for many accented characters, Spanish included.

    var input = "La introducción masiva de las nuevas tecnologías de la información";
    var utf8bytes = Encoding.UTF8.GetBytes(input);
    var win1252Bytes = Encoding.Convert(
                    Encoding.UTF8, Encoding.GetEncoding("windows-1252"), utf8bytes);
    File.WriteAllBytes(@"foo.txt", win1252Bytes);
    

提交回复
热议问题