Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iPhone - Comparing strings with a German umlaut

I've few German strings (with umlauts like åä etc) in NSArray. For example consider a word like "gënder" is there in array. User enters "gen" in a text field. I can to check the words in string that matches the characters "gen". How can I compare the string by consider umlauts as english strings...? So in above example, when user enters "gen", it has to return "gënder".

Is there any solution for this type of comparision?

like image 495
Satyam Avatar asked Dec 28 '22 13:12

Satyam


1 Answers

Use the NSDiacriticInsensitiveSearch option of the various NSString compare methods. As described in the documentation:

Search ignores diacritic marks. For example, ‘ö’ is equal to ‘o’.

For example:

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");
}
like image 165
titaniumdecoy Avatar answered Jan 18 '23 16:01

titaniumdecoy