在Windows 11中使用Visual代码中的Rust时,我遇到了瑞典民族字符的问题。它可以用以下程序显示:
fn main() {
let abc = " ååå
ööö
äää";
println!("<---{}--->", abc);
}当程序使用"cargo run“从命令行运行时,输出如下:
<--- ååå
ööö
äää--->奇怪的是,在第2行和第3行的开头添加了空格。但是,当程序在Visual代码中运行时,瑞典字符会被扭曲。
<--- ååå
├╢├╢├╢
├ñ├ñ├ñ--->我该怎么解决呢?我负责文本处理,这是一个主要的问题。
编辑:由于在许多系统中没有出现问题,我添加了技术数据:Windows11ProVersion10.0.22621 Build 22621;Visual代码版本: 1.73.1 (用户设置)日期: 2022-11-09 Chromium: 102.0.5005.167 Node.js: 16.14.2沙箱: No。
VSC终端似乎使用cmd,因为所有cmd命令都可以工作。
编辑2:通过添加以下内容解决了这个问题:
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"/c",
"chcp.com 65001"
]
},
},作为settings.json中的第一个参数并保存更改。
发布于 2022-12-03 09:14:41
-这个答案是特定于Windows的。-
信息:这个答案描述了如何改变您的VSCode设置,以强制UTF-8在您的控制台。这个答案的另一种选择是强制使用UTF-8系统,如下所述:Using UTF-8 Encoding (CHCP 65001) in Command Prompt / Windows Powershell (Windows 10)。
看起来,有时Windows没有使用正确的UTF-8代码页。
您可以告诉VSCode使用以下设置强制其外壳中的代码页。
打开Ctrl+,)
Settings页面,鼠标上方的文本显示"Open (JSON)“)
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": [
"-NoExit",
"/c",
"chcp.com 65001"
]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [
"/K",
"chcp 65001"
],
"icon": "terminal-cmd"
},
},这将强制使用UTF-8代码页。
如果工作正常,打开一个新的shell应该显示Active code page: 65001。
来源:https://github.com/microsoft/vscode/issues/19837
以前的、不推荐的设置:
如果您的外壳是"Powershell":“
https://stackoverflow.com/questions/74665076
复制相似问题