Ruby和Python等语言都支持字符串块.如:
a = '''
Hello
World
'''
Run Code Online (Sandbox Code Playgroud)
Swift是否支持字符串块?
否.正如Swift编程语言介绍的词汇结构中所述,字符串文字包含在一对引号中,不得包含换行符.
语法指定:
string-literal→"quoted-text"
quoted-text→quoted-text-item quoted-text opt
quoted-text-item→escaped-character
quoted-text-item→(expression)
quoted-text-item→任何Unicode扩展字形群集除了",\,U + 000A或U + 000D
[...]
其中U + 000A和U + 000D分别是换行符和回车符.
目前,没有其他类型的字符串文字.