Let's say I have a string "Hello %s. How are you %s" and I want to put the same string in both of %s. The obvious option is to use:
fmt.Printf("Hello %s. How are you %s", "KK", "KK") // returns "Hello KK. How are you KK"
is there a way to index the parameters so that I don't have to repeat "KK"?
Found a way to do it. The syntax is as follows:
where
%[1]srepresents the first parameter after the string that is being formatted. You can also do something like this: