IPhone - Compare strings with German umlaut

I have several German strings (with umlauts like åä, etc.) in NSArray. For example, in an array there is a word like "gënder". The user enters the "gene" in the text box. I can check the words in a string that matches the characters "gen". How can I compare a string by treating umlauts as English strings ...? Therefore, in the above example, when the user enters a "gene", he should return a "gënder".

Is there any solution for this type of comparison?

+4
source share
1 answer

Use the NSDiacriticInsensitiveSearch parameter for various NSString comparison methods. As described in the documentation:

Search ignores diacritics. For example, 'ö is equal to' o.

For instance:

 NSString *text = @"gënder"; NSString *searchString = @"ender"; NSRange rng = [text rangeOfString:searchString options:NSDiacriticInsensitiveSearch]; if (rng.location != NSNotFound) { NSLog(@"Match at %@", NSStringFromRange(rng)); } else { NSLog(@"No match"); } 
+10
source

All Articles