3

I need to compare 2 strings, looking at the first letter only.

Is there a method to compare A to Á, and recognize it as A, without the ´?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Rui Lopes
  • 2,562
  • 6
  • 34
  • 49
  • 1
    Check out this answer, which has what you need: http://stackoverflow.com/questions/1231764/nsstring-convert-to-pure-alphabet-only-i-e-remove-accentspunctuation/1233399#1233399 – martineno Dec 11 '10 at 21:19

1 Answers1

6

NSString has a diacritic-insensitive comparison mode which will do what you're after.

// should return NSOrderedSame, i.e. identical
[@"Apple" compare:@"Ápple" 
          options:NSDiacriticInsensitiveSearch]

If you want it to be case-insensitive as well:

// ditto
[@"APPLE" compare:@"Ápple" 
          options:NSDiacriticInsensitiveSearch | NSCaseInsensitiveSearch] 
Noah Witherspoon
  • 57,021
  • 16
  • 130
  • 131