I have a situation where I want to use my printf argument twice.
printf
fmt.Printf("%d %d", i, i)
Is there a way to tell fmt.Printf to just reuse the same i?
fmt.Printf
i
fmt.Printf("%d %d", i)
You can use the [n] notation to specify explicit argument indexes like so:
[n]
fmt.Printf("%[1]d %[1]d ", i)
Here is a full example you can experiment with: http://play.golang.org/p/Sfaai-XgzN
1.4m articles
1.4m replys
5 comments
57.0k users