我在 fmt.Sprintf 中有很长的一行。我如何在代码中拆分它?我不想将所有内容都放在一行中,这样代码看起来很难看。
fmt.Sprintf("a:%s, b:%s ...... this goes really long")
最佳答案
使用string concatenation在多行上构造单个字符串值:
fmt.Sprintf("a:%s, b:%s " +
" ...... this goes really long",
s1, s2)
这个例子中的长字符串是在编译时构建的,因为字符串连接是一个常量表达式。
您可以使用 raw string literal 在包含的换行符处拆分字符串:
fmt.Sprintf(`this text is on the first line
and this text is on the second line,
and third`)
关于go - 如何拆分 fmt.sprintf 的长行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35142532/