File.ReadAllText中的无效字符 [英] Invalid characters in File.ReadAllText

查看:122
本文介绍了File.ReadAllText中的无效字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调用旨在格式化某些文件格式的程序中的 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 重载,它允许您指定正确的<$ c $读取文件时使用c>编码。

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中的无效字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆