Accent insensitive string comparison?

后端 未结 2 1403
渐次进展
渐次进展 2020-12-20 12:12

Is there any way to do an accent insensitive string comparison? For example, é == e? I couldn\'t find any options to pass rangeOfString:options:. Any help is greatly appreci

相关标签:
2条回答
  • 2020-12-20 12:14

    You want to pass the NSDiacriticInsensitiveSearch option to whichever method you use (e.g. compare:options: or rangeOfString:options:)

    0 讨论(0)
  • 2020-12-20 12:23

    If you also want a substring search and have an array of items you want to filter I recommend this:

    [self.objects filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id  _Nullable evaluatedObject, NSDictionary<NSString *,id> * _Nullable bindings) {
        MyClass *object = (MyClass *)evaluatedObject;
        if ([object.name localizedStandardContainsString:filterString]) return YES;
        return NO;
    }]];
    
    0 讨论(0)
提交回复
热议问题