SWIFT 5は、ケースを無視して、配列が文字列が含まれているか否かを判断します

システム:MacのOS 10.15.2、XCodeの11.3、 SWIFT 5.0
書き込み時間:2020年1月8日

説明

SWIFT 5は、ケースを無視して、配列が文字列が含まれているか否かを判断します

let list = ["kAshif", "1", "2"]
let list2 = ["3", "4"]
let word = "Kashif"

if list.contains(where: { $0.caseInsensitiveCompare(word) == .orderedSame }) {
    print("list contains kAshif is true")
}

if list2.contains(where: { $0.caseInsensitiveCompare(word) == .orderedSame}) {
    print("list2 contains kAshif is true")
}

// print > list contains kAshif is true

参照

https://stackoverflow.com/questions/31329568/check-if-a-string-exists-in-an-array-case-insensitively/59644230#59644230

公開された127元の記事 ウォン称賛12 ビュー20000 +

おすすめ

転載: blog.csdn.net/zgpeace/article/details/103896507