case insensitive matching search in string array swift 3

前端 未结 4 484
余生分开走
余生分开走 2021-01-07 17:21

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          


        
4条回答
  •  时光取名叫无心
    2021-01-07 17:42

    localizedCaseInsensitiveContains
    Returns a Boolean value indicating whether the given string is non-empty and contained within this string by case-insensitive, non-literal search, taking into account the current locale. Locale-independent case-insensitive operation, and other needs, can be achieved by calling range(of:options:range:locale:).

    Equivalent to: range(of: other, options: .caseInsensitiveSearch, locale: Locale.current) != nil

    It's better to use

    .filter { $0.range(of: "india", options: .caseInsensitive) != nil }
    

提交回复
热议问题