swift語言中字元和字串連線的2種方式

2021-09-02 13:12:45 字數 1001 閱讀 1477

本人剛學swift,實現乙個小功能,將字串反轉,需要用到字元和字串的連線,

如下,在網上搜尋swif字元和字串連線,基本都是下面的這個例子:

let string1 = "hello"

let string2 = " there"

let character1: character = "!"

let character2: character = "?"

let stringpluscharacter = string1 + character1 // 等於 "hello!"

let stringplusstring = string1 + string2 // 等於 "hello there"

let characterplusstring = character1 + string1 // 等於 "!hello"

let characterpluscharacter = character1 + character2 // 等於 "!?"

我只想說,在我的xcode中 swift編譯根本行不通啊!!!行不通啊!!!行不通啊!!!

根據本人摸索和實驗,找到2種方法可以完成字元和字串的連線。

var string = "hello"

var character : character = "!";

println(string) //等於 「hello!」

//2. 使用stirng的構造方法

var str2 = string(character)

string += str2

println(string) //等於 「hello!」

最後想問下,怎麼樣檢視自己swift語言的版本啊

字串連線

輸入n個字串s i 你要把他們按某個順序連線起來,使得字典序最小。1 n 100 每個字串長度 100 字串只包含小寫字母 input 第一行乙個整數n。接下來每行乙個字串s i output 一行乙個字串表示把輸入的n個字串按某個順序連線之後的結果input示例 6 itlooks like an...

字串連線

mysql select abc 123 abc 123 123 1 row in set,1 warning 0.00 sec mysql select 123 123 123 123 246 1 row in set 0.00 sec mysql select 123 123 123 123 2...

字串連線

answer1 char型別 利用cin不包括空格的天然特性,讀取兩個字串,直接按序輸出 include include using namespace std int main return0 answer2 string型別 對於string型別變數,我們可以直接用 進行連線操作 include...