我想为多个项找到rangeOfString,并尝试使用带有for-in循环的数组,但是这只是循环到数组的最后一个项并将其用于rangeOfString。是否可以使用带有rangeOfString的数组,以便它同时搜索所有术语,或者我是否必须为每个术语单独编写rangeOfString。
while true {
let attempts = ["goodmorning","goodbye", "hello", "hi"]
for attempt in attempts{
tru = attempt
let range = text.rangeOfString(tru, options: [], range: searchRange)
答案 0 :(得分:0)
试试这个:
let attempts = ["goodmorning","goodbye", "hello", "hi"]
for attempt in attempts {
if text.rangeOfString(attempt) != nil {
print("found \(attempt)")
}
}