在Goland IDE的断点中,如何“评估和记录”格式化字符串?

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

How to "Evaluate and Log" a formatted string in Goland IDE breakpoint?

问题

我正在使用Goland中的“评估和记录”功能,只能打印字符串或变量。

如何记录一个包含变量值的字符串?我想要类似于"foo is now {fooVariableName}"的效果,但是Go语言没有格式化字符串的功能。

英文:

I'm using the "Evaluate and log" feature in Goland and can only print a string or a variable.

How can I log a string with a variable value embedded? I want something like "foo is now {fooVariableName}", but go doesn't have formatted strings.

答案1

得分: 1

这个IDE功能称为"evaluate",意思是你可以在其中放置一些表达式。所以你可以这样使用(如果你的变量是一个字符串):

"foo现在是" + fooVariableName

或者,如果你的变量是数字:

"foo现在是" + strconv.Itoa(fooVariableName)

然而,它似乎相当有限,因为你只能使用已经导入的函数。所以在上面的例子中,只有在你的模块的某个地方已经使用了strconv.Itoa,你才能使用它。

P.S. 我不知道这个函数,但是我尝试了一下,看起来很有用,尽管有点有限。

英文:

This IDE feature says "evaluate", which means you can put some expression there. So you can use something like this (if your variable is a string):

"foo is now " + fooVariableName

Or, if your variable is numeric

"foo is now " + strconv.Itoa(fooVariableName)

However it seems to be quite limited as you can only use already imported functions. So in example above you'll only be able to use strconv.Itoa if it's already used somewhere in your module.

P.S. I didn't know about this function, but tried and it looks useful, although a bit limited

huangapple
  • 本文由 发表于 2023年1月8日 20:53:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/75047908.html
匿名

发表评论

匿名网友

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

确定