I have application that stores string values from server. Then I am using SearchView for write string that can be in List. It must be case insensitive. So far I have this. But this is not the magic i am looking for.
if (myListTags as NSArray).containsObject(searchBar.text!) {
print("FOUND")
getCategoryPick()
}
I tried to join it with caseInsensitiveCompare
but i failed. Any help for me?
It would be perfect if that code can understand letter similarity in czech language .. (č = c, ž = z, í = i ......)
"č" is the Unicode character "LATIN SMALL LETTER C WITH CARON". It can be decomposed into "c" + "ˇ" where the latter (the "CARON") is a so-called "diacritical mark".
To ignore diacritical marks when comparing strings (so that
"č" = "c"), use the .DiacriticInsensitiveSearch
option:
let list = ["č", "ž"]
let search = "C"
if (list.contains {
$0.compare(search, options: [.DiacriticInsensitiveSearch, .CaseInsensitiveSearch]) == .OrderedSame
}) {
print("Found")
}
Or, if you want to find matching substrings:
if (list.contains {
$0.rangeOfString(search, options: [.DiacriticInsensitiveSearch, .CaseInsensitiveSearch]) != nil
}) {
print("Found")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With