我有两个字符串填充字符串,我希望识别两个数组中的匹配字符串。例如
var ArrayOne = ["Dog", "Cat", "Chicken"]
var Array Two = ["Dog", "Elephant", "Chicken", "Sheep"]
我希望结果是
["Dog", "Chicken"]
提前致谢
答案 0 :(得分:1)
var ArrayOne = ["Dog", "Cat", "Chicken"]
var ArrayTwo = ["Dog", "Elephant", "Chicken", "Sheep"]
var ArrayThree = [String]()
for animal in ArrayOne {
if ArrayTwo.contains(animal) {
ArrayThree.append(animal)
}
}