compare special characters like À with regular A

前端 未结 3 1307
北海茫月
北海茫月 2021-01-25 20:54

In some languages there are letters like À, I saw that for table view sections the native iOS put À under the same section as A.
I wan

相关标签:
3条回答
  • 2021-01-25 21:19

    You can convert it first into regular alphabets and then compare.

    NSString *originalStr = @"À béautiful day";
    NSData *d = [originalStr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *converted = [[NSString alloc] initWithData:d encoding:NSASCIIStringEncoding];
    
    0 讨论(0)
  • 2021-01-25 21:34

    Don't convert or transform as per the other answers. First, try -[NSString localizedStandardCompare:]. If that doesn't do what you want, pass NSDiacriticInsensitiveSearch among the options to one of the NSString comparison methods (such as -compare:options:range:locale:). You may want to use additional options, too, such as NSCaseInsensitiveSearch.

    0 讨论(0)
  • 2021-01-25 21:44

    Here's a great article about CFStringTransform on NSHipser http://nshipster.com/cfstringtransform/

    Next, apply the kCFStringTransformStripCombiningMarks transform to remove any diacritics or accents.

    0 讨论(0)
提交回复
热议问题