检查字符串是否不区分大小写地存在于数组中 [英] Check if a string exists in an array case insensitively
本文介绍了检查字符串是否不区分大小写地存在于数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
声明:
let listArray = ["kashif"]
let word = "kashif"
然后,此
contains(listArray, word)
返回true,但如果声明为:
Returns true but if declaration is:
let word = "Kashif"
然后它返回false,因为比较是区分大小写的。
then it returns false because comparison is case sensitive.
如何使此比较不区分大小写?
How to make this comparison case insensitive?
推荐答案
您可以使用
word.lowercaseString
将字符串转换为所有小写字符
to convert the string to all lowercase characters
这篇关于检查字符串是否不区分大小写地存在于数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文