从包含字符串另一个阵列迅速返回的数组 [英] swift return array from another array with contain string
本文介绍了从包含字符串另一个阵列迅速返回的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我们有包含例如字符串数组{houssam,哈桑,塔勒布}
if we have an array that contain strings for example {"houssam","hassan","taleb"}
和我们有一个字符串=SS
and we have a string = "ss"
我需要返回返回包含SS字符串数组,所以在这种情况下,我们有{houssam,哈桑}
I need to return an array that return the string which contain ss, so in this case we have {"houssam","hassan"}
什么是做到这一点的最好的方法?
What is the best method to do that?
谢谢,
推荐答案
您可以试试这个:
let string = "ss"
let array = ["houssam","hassan","taleb"]
let filtered = array.filter() { $0.containsString(string) }
这篇关于从包含字符串另一个阵列迅速返回的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文