gpt4 book ai didi

c# - File.ReadAllText 中的无效字符

转载 作者:太空狗 更新时间:2023-10-29 18:02:23 24 4
gpt4 key购买 nike

我在一个旨在格式化我拥有的一些文件的程序中调用 File.ReadAllText()

其中一些文件包含 ® (174) 符号。但是,当读取文本时,返回的字符串包含 (65533) 符号,而 ® (174) 应该在其中。

什么会导致这种情况,我该如何解决?

最佳答案

文件很可能包含与默认编码不同的编码。如果您知道,可以使用 File.ReadAllText Method (String, Encoding) 指定它覆盖。

代码示例:

string readText = File.ReadAllText(path, Encoding.Default);  // <-- change the encoding to whatever the encoding really is

如果您不知道编码,请参阅之前的 SO 问题:How to use ReadAllText when file encoding unknown

关于c# - File.ReadAllText 中的无效字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15480970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com