你如何在 Go 中编写多行字符串? [英] How do you write multiline strings in Go?

查看:22
本文介绍了你如何在 Go 中编写多行字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Go 有没有类似于 Python 的多行字符串:

Does Go have anything similar to Python's multiline strings:

"""line 1
line 2
line 3"""

如果不是,写跨越多行的字符串的首选方式是什么?

If not, what is the preferred way of writing strings spanning multiple lines?

推荐答案

根据语言规范 您可以使用原始字符串文字,其中字符串由反引号而不是双引号分隔.

According to the language specification you can use a raw string literal, where the string is delimited by backticks instead of double quotes.

`line 1
line 2
line 3`

这篇关于你如何在 Go 中编写多行字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆