Escape Variables with Printf

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

Escape Variables with Printf

问题

如果我想要做以下操作:

fmt.Printf("Escape this -> %v... Do not escape this -> %v", "Unescaped")

我该如何转义第一个 %v 的出现?

\%v 似乎不起作用。有什么想法吗?

英文:

If I wanted to do the following:

fmt.Printf("Escape this -> %v... Do not escape this -> %v", "Unescaped")

How could I escape the first occurrence of %v?

\%v doesn't seem to work. Any ideas?

答案1

得分: 139

你可以使用 %% 来表示百分号。

%% 表示一个字面上的百分号,不会消耗任何值

https://golang.org/pkg/fmt/

英文:

You can use %% for literal %

%%	a literal percent sign; consumes no value

https://golang.org/pkg/fmt/

huangapple
  • 本文由 发表于 2016年2月28日 18:57:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/35681595.html
匿名

发表评论

匿名网友

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

确定