问题
When trying to use the += operator to append a Character to a String, I'm getting the following error:
String is not identical to UInt8
The error occurs on the puzzleOutput += char line in the code below:
let puzzleInput = "great minds think alike "
var puzzleOutput = ""
for char in puzzleInput
{
switch char
{
case "a","e","i","o","u":
continue
default:
puzzleOutput += char
}
}
println(puzzleOutput)
How can I append a Charater to a String?
回答1:
The use of += to append a Character to a String was intentionally deleted from the language several betas ago. Use
puzzleOutput.append(char)
instead.
来源:https://stackoverflow.com/questions/26029011/error-using-to-append-a-character-to-a-string-string-is-not-identical-to-uin