【问题解决】VS提示Some bytes have been replaced with the Unicode substitution character
VS提示Some bytes have been replaced with the Unicode substitution character while loading file xxxxx with Unicode(UTF-8) encoding. Saving the file will not preserve the original file contents.
中文意思,是在打开xxxxx文件时,部分字符被替换成Unicode(UTF-8)格式,保存文件将会无法保留原来的内容(原来的内容将会被替换成Unicode)
【背景】
在Visual Studio 2022版本中,打开非UTF-8格式的代码,会同时提示以上内容。从内容推断,应当是某个程序在打开文件时,对文件的编码进行了调整。导致问题发生。
【环境】
系统:Windows 10
开发环境:Visual Studio 2022
【解决思路】
找到有可能修改文件编码格式的可能性。包括VS自带的插件,工具。或者是系统的某些设定。
在控制面板中,有一个"使用Unicode UTF-8提供全球语言支持"。当文本未指定编码格式时,将默认作为UTF-8编码进行处理。这样会导致GB2312编码格式的文件被当做UTF-8进行解析。遇到无法解析的字符,将会报错。
【解决方案】
- 打开"控制面板"
- 选择"时钟与区域"
- 选择"区域",切换到"管理"Tab
- 点击"更改系统区域设置"
- 取消"Beta版:使用Unicode UTF-8提供全球语言支持"
- 重启电脑。