[英]Wrong diacritic letters in Integrated Terminal of Visual Studio Code with PowerShell between Run and Run Selection
I have the Windows 10 with Windows-1250 encoding but in Visual Studio Code with integrated terminal I have problems with diacritic signs:我有带有 Windows-1250 编码的 Windows 10,但在带有集成终端的 Visual Studio Code 中,我遇到了变音符号的问题:
As you see encoding is different between Run and Run Selection of same command: write-host "Wspólny"
My JSON user configuration is empty, I've been trying for several hours but no solution helps.如您所见,同一命令的运行和运行选择之间的编码不同: write-host "Wspólny"
我的 JSON 用户配置为空,我已经尝试了几个小时,但没有解决方案有帮助。 I want UTF-8 everywhere.我想要 UTF-8 无处不在。
The most likely explanation:最可能的解释:
You're running Windows PowerShell , which reads its source code based on the system's active ANSI code page ( 1250
in your example).您正在运行Windows PowerShell ,它根据系统的活动 ANSI 代码页(在您的示例中为1250
)读取其源代码。
By contrast, Visual Studio Code creates BOM-less UTF-8 -encoded files by default.相比之下,Visual Studio Code 默认创建无 BOM 的 UTF-8编码文件。
In the absence of a BOM in a source code file (or any text file that Windows PowerShell reads, such as with Get-Content
), ANSI encoding is assumed, so the UTF-8 file is misinterpreted .如果源代码文件(或 Windows PowerShell 读取的任何文本文件,例如使用Get-Content
)中没有 BOM,则假定为ANSI编码,因此 UTF-8 文件被误解。
Specifically, each individual byte of any non-ASCII character - which in UTF-8 is always encoded as a multi-byte sequence - is then interpreted as an ANSI character.具体来说,任何非 ASCII 字符的每个单独字节——在 UTF-8 中总是被编码为多字节序列——然后被解释为 ANSI 字符。
Note: This is no longer a problem in PowerShell (Core) 7+, which consistently defaults to UTF-8, both on reading BOM-less files and when writing files (BOM-less UTF-8).注意:这在 PowerShell (Core) 7+ 中不再是问题,它始终默认为 UTF-8,无论是在读取 BOM-less 文件时还是在写入文件时(BOM-less UTF-8)。
Therefore, the solution is to save your source code - or any UTF-8 files you want Windows PowerShell to read correctly - as UTF-8 with BOM .因此,解决方案是保存您的源代码- 或您希望 Windows PowerShell 正确读取的任何 UTF-8 文件 -作为ZAE3B3ZDF9970B5BC956727正确读取。
You also need to do this for source code you want to run properly in both editions of PowerShell.您还需要为希望在 PowerShell 的两个版本中正常运行的源代码执行此操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.