【发布时间】:2018-08-01 01:20:37
【问题描述】:
我正在尝试将字符串 (userInput) 与字符串数组 (groupA) 进行比较,以检查 groupA 中有多少项存在于 userInput 中。
var groupA = ["game of thrones", "star wars", "star trek" ]
var userInput = "My name is oliver i love game of thrones, star wars and star trek."
var count = 0
func checking() -> Int {
for item in groupA {
// alternative: not case sensitive
if userInput.lowercased().range(of:item) != nil {
count + 1
}
}
return count
}
func Printer() {
print(count)
}
【问题讨论】:
-
澄清一下,上面的代码不行吗?
标签: arrays swift string-matching