开发者

iPhone - Comparing strings with a German umlaut

开发者 https://www.devze.com 2023-04-10 13:18 出处:网络
I\'开发者_StackOverflow中文版ve few German strings (with umlauts like åä etc) in NSArray. For example consider a word like \"gënder\" is there in array.

I'开发者_StackOverflow中文版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?


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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号