我試圖使用「+ =」將字符附加到字符串,但它並不真正起作用。 一旦我嘗試使用append方法,它的工作原理。我只是想知道爲什麼。 編譯器說「字符串與Unit8不相同」。將字符附加到Swift中的字符串
let puzzleInput = "great minds think alike"
var puzzleOutput = " "
for character in puzzleInput {
switch character {
case "a", "e", "i", "o", "u", " ":
continue
default:
// error : doesn't work
puzzleOutput += character
//puzzleOutput.append(character)
}
}
println(puzzleOutput)
僅供參考,如果你把它會工作'字符'首先是字符串:'puzzleOutput + = String(字符)'。 – 2014-09-25 01:58:16