\"" book.go parsing -6ren">
gpt4 book ai didi

go - 如何使用 gofmt 将单引号替换为双引号

转载 作者:数据小太阳 更新时间:2023-10-29 03:31:59 25 4
gpt4 key购买 nike

我使用 go 1.6,我喜欢使用单引号。完成文件编辑后,我想在我的终端中使用 gofmt 替换它们,但没有任何效果。

    gofmt -r "'->\"" book.go
parsing pattern ' at 1:1: rune literal not terminated

我使用 zsh。

最佳答案

$ go doc cmd/gofmt

Gofmt formats Go programs.

The flags are:

-r rule
Apply the rewrite rule to the source before reformatting.

The rewrite rule specified with the -r flag must be a string of the form:

pattern -> replacement

Both pattern and replacement must be valid Go expressions. In the pattern, single-character lowercase identifiers serve as wildcards matching arbitrary sub-expressions; those expressions will be substituted for the same identifiers in the replacement.


The Go Programming Language Specification

Expressions

An expression specifies the computation of a value by applying operators and functions to operands.


模式和替换都必须是有效的 Go 表达式。

关于go - 如何使用 gofmt 将单引号替换为双引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35782213/

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