Replace all variables in Sprintf with same variable
问题 Is it possible using fmt.Sprintf() to replace all variables in the formatted string with the same value? Something like: val := "foo" s := fmt.Sprintf("%v in %v is %v", val) which would return "foo in foo is foo" 回答1: It's possible, but the format string must be modified, you must use explicit argument indicies: Explicit argument indexes: In Printf, Sprintf, and Fprintf, the default behavior is for each formatting verb to format successive arguments passed in the call. However, the notation