增加了 # 符號齿诉,使得寫字符串更加簡單。
-
在字符串中包含 " 時不必再加 \
//before let rain = "The is\"new\"string" //after let rain = #"The is"new"string"#
-
包含 \ 反斜杠也不需要再加轉(zhuǎn)義符
//before let rain = "The is\\new string" //after let rain = #"The is \new string"#
由于反斜杠作為字符串中的字符晌姚,所以在插入值的時候需要在后面再加個 #
-
//before let age = 26 let dontpanic = "myAge is \(age)" // after let answer = 26 let dontpanic = #"myAge is \#(age)"#
*當字符串包含 # 時粤剧, 前后應用 ## 包裹字符串
let str = ##"this is "a"#good ideal"##
*用 #""" 開頭 """#結(jié)尾 來表示多行字符串
let multiline = #"""
The answer to life,
the universe,
and everything is \#(answer).
"""#
-
由于不用反斜杠轉(zhuǎn)義 使得正則表達式更加簡潔明了
//before let regex1 = "\\\\[A-Z]+[A-Za-z]+\\.[a-z]+" //after let regex2 = #"\\[A-Z]+[A-Za-z]+\.[a-z]+"#