Swift連接字串和字元

來源:互聯網
上載者:User

標籤:

 1 字串和字元的值可以通過加法運算子 (+) 相加在一起並建立一個新的字串值: 2 let string1 = "hello" 3 let string2 = " there" 4 let character1: Character = "!" 5 let character2: Character = "?" 6 let stringPlusCharacter = string1 + character1 // 等於 "hello!" 7 let stringPlusString = string1 + string2 // 等於 "hello there" 8 let characterPlusString = character1 + string1 // 等於 "!hello" 9 let characterPlusCharacter = character1 + character2 // 等於 "!?" 10 您也可以通過加法賦值運算子 (+=) 將一個字串或者字元添加到一個已經存在字串變數上:11 var instruction = "look over"12 instruction += string213 // instruction 現在等於 "look over there"14 var welcome = "good morning"15 welcome += character116 // welcome 現在等於 "good morning!" 17 注意:您不能將一個字串或者字元添加到一個已經存在的字元變數上,因為字元變數只能包含一個字元。

 

Swift連接字串和字元

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.