【发布时间】:2017-09-27 10:09:15
【问题描述】:
感谢您的帮助 - 刚开始,所以想象一下我的逻辑存在一些严重问题。
尝试编写程序,给定一个输入,如果在字典中找到来自该输入的字母,则将该字母替换为相应的值。
真的卡在我要去的地方。任何人都可以帮助/建议一种可行的替代逻辑吗?
var leetDic = ["A" : "4",
"B" : "6",
"E" : "3",
"I" : "1",
"L" : "1",
"M" : "(V)",
"N" : "(/)",
"O" : "0",
"S" : "5",
"T" : "7",
"V" : "(/",
"W" : "`//]"]
func leetConverter(leet: String) {
var leet1 = leet.uppercased()
for i in leet1.characters {
if i == leetDic.keys { //ERROR "Binary operator cannot be applied to operands of type Character and dictionary"
i = leetDic.values // ERROR "cannot assign value 'i' is a let constant"
} else {
return i
}
}
}
var test = leetConverter(leet: "Hello World")
【问题讨论】:
标签: swift string function dictionary