我正在调用旨在格式化某些文件格式的程序中的 File.ReadAllText()。
I'm calling File.ReadAllText() in a program designed to format some files that I have.
其中一些文件包含®(174)符号。但是,在读取文本时,返回的字符串包含。(65533)符号,其中®(174)应该。
Some of these files contain the ® (174) symbol. However, when the text is being read, the returned string contains � (65533) symbols where the ® (174) should be.
是什么原因引起的,我该如何解决?
What would cause this and how can I fix it?
推荐答案这可能是由于编码中的不匹配。使用 ReadAllText 重载,它允许您指定正确的编码。
This is likely due to a mismatch in the Encoding. Use the ReadAllText overload which allows you to specify the proper Encoding to use when reading the file.
默认重载将假定为UTF-8,除非它可以检测到UTF-32。其他任何编码都会不正确。
The default overload will assume UTF-8 unless it can detect UTF-32. Any other encoding will come through incorrectly.
更多推荐
File.ReadAllText中的无效字符
发布评论