问题
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 want to do the same thing, I'm building my sections by comparing the first letter, so I need that À will be equal to A.
I tried using localizedCompare but still I didn't got that those two are equal.
Is there a way to to this kind of compare? or to normalised À so it will be A ?
回答1:
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.
回答2:
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];
回答3:
Here's a great article about CFStringTransform on NSHipser http://nshipster.com/cfstringtransform/
Next, apply the kCFStringTransformStripCombiningMarks transform to remove any diacritics or accents.
来源:https://stackoverflow.com/questions/22893626/compare-special-characters-like-%c3%80-with-regular-a