将字符附加到字符串时出错

将字符附加到字符串时出错

本文介绍了使用+ =将字符附加到字符串时出错:字符串与UInt8不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当尝试使用+=运算符将Character附加到String时,出现以下错误:

When trying to use the += operator to append a Character to a String, I'm getting the following error:

该错误在以下代码的puzzleOutput += char行上发生:

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)

如何将Charater附加到String?

推荐答案

在多个测试版中,故意从++语言中将字符附加到字符串中已被删除.使用

The use of += to append a Character to a String was intentionally deleted from the language several betas ago. Use

相反.

这篇关于使用+ =将字符附加到字符串时出错:字符串与UInt8不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:00