Comparing NSStrings with Ä, Ö, Ü

I got a strange problem. I have UITextField and NSString that I want to compare using the isEqualtoString method. So far, the lines do not include German Umlaute, such as Ä, Ö, Ü everything works fine, but if they do, it no longer works. NSLog correctly displays Umlaute strings.

 NSLog([currentAnswer lowercaseString]);
 NSLog([[self.antwortTextField text]lowercaseString]);

if ([[currentAnswer lowercaseString] isEqualToString:[[self.antwortTextField text]lowercaseString]]) {......}

Do I need to format strings? This problem is driving me crazy!

+3
source share
1 answer

You can use the advanced comparison method NSString, for example:

- (NSComparisonResult)compare:(NSString *)aString
                      options:(NSStringCompareOptions)mask
                        range:(NSRange)range
                       locale:(id)locale

and then specify additional parameters. Specific parameters that may interest you:

  • NSCaseInsensitiveSearch
  • NSDiacriticInsensitiveSearch
  • NSWidthInsensitiveSearch
+4
source

All Articles