gpt4 book ai didi

swift - 快速连接字符时出错

转载 作者:搜寻专家 更新时间:2023-11-01 05:49:03 24 4
gpt4 key购买 nike

我试图在 Swift 中连接两个字符,但它显示错误

Binary operator can't be applied on two character operands.

let a: Character = "A"
let l: Character = "l"

let al = a + l

Swift 的字符串支持运算符重载,为什么字符不支持?

最佳答案

你可以将一个字符追加到一个字符串中

let a: Character = "A"
let l: Character = "l"

var al = ""

al.append(a)
al.append(l)

println(al) // "Al"

或者连接两个字符串

let a = "A"
let l = "l"

let al = a + l // "Al"

关于swift - 快速连接字符时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31415094/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com