Swift3 搜索字符串swift 3.0中的数组元素
我想搜索字符串中字符串数组的元素。像这样:Swift3 搜索字符串swift 3.0中的数组元素,swift3,Swift3,我想搜索字符串中字符串数组的元素。像这样: let array:[String] = ["dee", "kamal"] let str:String = "Hello all how are you, I m here for deepak." 所以,我想要 str.contain("dee") == true 在字符串中进行任何可能的搜索?您应该迭代数组,并为每个元素调用str.contains for word in array { if str.contains(word) {
let array:[String] = ["dee", "kamal"]
let str:String = "Hello all how are you, I m here for deepak."
所以,我想要
str.contain("dee") == true
在字符串中进行任何可能的搜索?您应该迭代数组,并为每个元素调用
str.contains
for word in array {
if str.contains(word) {
print("\(word) is part of the string")
} else {
print("Word not found")
}
}
您应该迭代数组,并为每个元素调用
str.contains
for word in array {
if str.contains(word) {
print("\(word) is part of the string")
} else {
print("Word not found")
}
}
您可以在一行中编写一个正则表达式模式
“(item1 | item2 | item3)”
您可以在一行中编写一个正则表达式模式
“(item1 | item2 | item3)”
您可以这样做:
array.forEach { (item) in
var isContains:Bool = str.contains(item)
print(isContains)
}
您可以这样做:
array.forEach { (item) in
var isContains:Bool = str.contains(item)
print(isContains)
}