2017-11-11 40 views
0

是什麼意思,當他們說使用三雙引號(‘’「),對於佔用多行串「的閉幕式報價?斯威夫特4編程三重引號

的壓痕匹配」。只要符合收盤報價的縮進,每個報價行開始時的縮進就會被移除。例如:

讓利報價=「」「 儘管有空格左邊, 實際的線都沒有縮進 除此之外線 雙引號。(」),不需要轉義可以出現。

我仍然有(蘋果+橘子)果粒的。 「」」 創建使用方括號([])陣列和詞典,和通過寫在括號內的索引或鍵訪問他們的元件A逗號的最後一個元素之後允許的。「。

摘自:蘋果公司「 。雨燕的編程語言(斯威夫特4)」的iBooks https://itunes.apple.com/us/book/the-swift-programming-language-swift-4/id881256329?mt=11

+3

我強烈建議開啓* Xcode的操場*和這個東西玩耍......你可能會驚訝你發現什麼;) –

回答

3

這是三個情景我能想到的解釋是:

這裏文本和三重引號左對齊

檢查輸出中,這裏的文本存儲,並沒有在每個段落的開頭一個空格打印。

let textSample1 = """ 
Test 1: Hello how are you welcome to the test 
something else is written here 
that's enough said 
""" 

print(textSample1) 

這裏文本具有間距在開始時,但在三重引號中的左對齊

檢查輸出中,這裏的文本存儲,並在每個段落,因爲的開頭用空格打印肚子在左邊引號,他們考慮了段落中的那些空格。

let textSample2 = """ 
    Test 2: Hello how are you welcome to the test 
    something else is written here 
    that's enough said 
""" 

print(textSample2) 

這裏文本具有間距在開始時和三重引號也被隔開,

檢查輸出中匹配的文本,這裏的文本存儲,並在開始時無空格打印儘管我們有把空間在beginging,這是因爲三引號處於同一水平文本,而不是空間的地方,這樣他們的空間將被忽略。我發現這是方便當你想多行文本存儲代碼,但想希望保持一些代碼其他用途這間格式化。

let textSample3 = """ 
    Test 3: Hello how are you welcome to the test 
    something else is written here 
    that's enough said 
    """ 

print(textSample3) 

輸出:

Test 1: Hello how are you welcome to the test 
something else is written here 
that's enough said 

    Test 2: Hello how are you welcome to the test 
    something else is written here 
    that's enough said 

Test 3: Hello how are you welcome to the test 
something else is written here 
that's enough said