Error using += to append a Character to a String: String is not identical to UInt8

狂风中的少年 提交于 2019-12-13 14:09:44

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!