Go语言长字符串:使用反引号(`)创建多行字符串
在Go语言中,长字符串可以使用反引号(`)包裹起来。反引号可以包含多行文本,并且会保留文本中的格式和空格。
例如:
package main
import "fmt"
func main() {
longString := `
This is a long string
that spans multiple lines
and preserves the formatting.
`
fmt.Println(longString)
}
上面的代码中,longString是一个长字符串,包含多行文本。使用反引号包裹起来可以保留文本中的换行和空格。运行上面的代码,会输出:
This is a long string
that spans multiple lines
and preserves the formatting.
可以看到,输出的字符串保留了原本的格式和空格。
原文地址: https://www.cveoy.top/t/topic/pCZt 著作权归作者所有。请勿转载和采集!