字符串数组swift 3中不区分大小写的匹配搜索 [英] case insensitive matching search in string array swift 3
本文介绍了字符串数组swift 3中不区分大小写的匹配搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Swift 3中,我想从字符串数组创建一个匹配字符串数组(不区分大小写):-
In Swift 3, I want to create an array of matching string (case insensitive) from string array:-
我正在使用此代码,但是区分大小写,
I am using this code, but it is case sensitive,
let filteredArray = self.arrCountry.filter { $0.contains("india") }
我该怎么做.. 假设我有一个名为arrCountry的主字符串数组,我想创建其中包含"india"(不区分大小写)的所有字符串的其他数组.
how can I do this.. suppose I have a master string array called arrCountry, I want to create other array of all the string who has "india"(case insensitive) in it.
有人可以帮我吗?
推荐答案
您可以尝试使用localizedCaseInsensitiveContains
let filteredArray = self.arrCountry.filter { $0.localizedCaseInsensitiveContains("india") }
这篇关于字符串数组swift 3中不区分大小写的匹配搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文