是否有一种简单的方法来在Go中格式化字符串而不打印字符串?
我可以:
bar := "bar"
fmt.Printf("foo: %s", bar)
Run Code Online (Sandbox Code Playgroud)
但我希望返回格式化的字符串而不是打印,以便我可以进一步操作它.
我也可以这样做:
s := "foo: " + bar
Run Code Online (Sandbox Code Playgroud)
但是当格式字符串很复杂时很难读取,当一个或多个部分不是字符串并且必须先转换时很麻烦,就像
i := 25
s := "foo: " + strconv.Itoa(i)
Run Code Online (Sandbox Code Playgroud)
我是Go的新手 - 我的背景是Ruby,这很简单.有更简单的方法吗?