Sprint & Sprintf
Sprint 使用其操作数的默认格式格式化并返回结果字符串。
当两者都不是字符串时,在操作数之间添加空格。
// Sprint formats using the default formats for its operands and returns the resulting string.
// Spaces are added between operands when neither is a string.
func Sprint(a ...any) string {
p := newPrinter()
p.doPrint(a)
s := string(p.buf)
p.free()
return s
}
Sprintf 根据格式说明符格式化并返回结果字符串。
// Sprintf formats according to a format specifier and returns the resulting string.
func Sprintf(format string, a ...any) string {
p := newPrinter()
p.doPrintf(format, a)
s := string(p.buf)
p.free()
return s
}
标签:语言,format,学习,字符串,Sprintf,formats,gogogo,Sprint,string
From: https://www.cnblogs.com/leejk/p/16739620.html