File.ReadAllText中的无效字符

编程入门 行业动态 更新时间:2024-10-09 06:29:41
本文介绍了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 重载,它允许您指定正确的编码。

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中的无效字符

本文发布于:2023-11-03 23:55:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1556420.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   File   ReadAllText

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!