目标很简单。从 .txt 文件中获取一些包含特殊字符的法语文本并将其粘贴到变量“content”中。除了字符“à”的所有实例都被解释为“À”之外,一切都运行良好。我选择了错误的编码(UTF7)还是什么?
任何帮助将非常感激。
// Using ecoding to ensure special characters work
Encoding enc = Encoding.UTF7;
// Make sure we get all the information about special chars
byte[] fileBytes = System.IO.File.ReadAllBytes(path);
// Convert the new byte[] into a char[] and then into a string.
char[] fileChars = new char[enc.GetCharCount(fileBytes, 0, fileBytes.Length)];
enc.GetChars(fileBytes, 0, fileBytes.Length, fileChars, 0);
string fileString = new string(fileChars);
// Insert the resulting encoded string "fileString" into "content"
content = fileString;