从/在VSCODE中删除无效字符

huangapple go评论110阅读模式
英文:

Getting rid of invalid character from/in VSCODE

问题

我是一个全新的Golang开发者,但是在使用VSCODE时遇到了一些问题。这种情况时有发生,有时候给我调试代码带来了很多麻烦。我不确定如何解决这个问题。

我附上了两张图片作为参考,

第一张图片中有一个无效字符:
从/在VSCODE中删除无效字符

然后,我用另一个编辑器打开了同样的文件,这是我得到的结果:

用另一个编辑器打开的相同代码:
从/在VSCODE中删除无效字符

问题是,这是自动发生的,我不确定问题出在哪里。如果你有解决办法,可以在不更换编辑器的情况下避免这个问题,请告诉我。

提前感谢你的帮助。

英文:

I am a totally new Golang developer, But I am facing some problem while using VSCODE. It's it's happening from time to time. It's giving me a lot of headache sometimes to debug my code. I am not sure how to fix this issue.
I am adding two images for reference ,

The first Image, There is an invalid character
从/在VSCODE中删除无效字符

Then, I have opened the same file with another editor, And here is what I got

Same Code with another Editor
从/在VSCODE中删除无效字符

The problem is, This is happening automatically. I am not sure where the problem is. If you have a solution about how to avoid this without changing my editor , Please let me know.

Thank you in advance.

答案1

得分: 2

首先,请在你的问题中包含源代码 - 我知道你想展示语法高亮 - 但这有助于用户更容易地重现问题。


由于Go源代码是以UTF-8编码的Unicode文本,因此在从浏览器格式化的代码中复制粘贴时,可能会出现不可见的“gremlin”字符。请参考这个示例

由于你正在使用VScode,我推荐使用这个扩展来突出显示源代码中的异常字符。


你的原始代码存在许多类型不匹配等问题。

修复其中一些问题,使代码能够编译/运行:

func main() {
    k := 3   // int
    b := 2.5 // float64
    var g float32
    g = float32(k) * float32(b) // 需要类型转换以获得所需的 float32
    fmt.Println(g)              // 引用 g - 避免"go vet"错误:"g declared but not used"
}

https://go.dev/play/p/XQCEMya-BlN

英文:

Firstly, please include the source code in your questions - I know you wanted to show the syntax highlighting - but it helps users to reproduce the problem more easily.


Since Go source is Unicode text encoded in UTF-8 it is possible that non-visible "gremlin" characters can creep in - especially when cut-n-pasting from a browser formatted code. Take a look at this example.

Since you are using VScode I recommend this extension to highlight rogue characters within your source code.


Your original code has many issues stemming from mismatched types etc.

Fixing some of these, enables the code to compile/run:

func main() {
	k := 3   // int
	b := 2.5 // float64
	var g float32
	g = float32(k) * float32(b) // need type conversion to get desired float32
	fmt.Println(g)              // reference g - to avoid "g declared but not used" go vet error
}

https://go.dev/play/p/XQCEMya-BlN

huangapple
  • 本文由 发表于 2021年12月1日 00:49:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/70173049.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定