Does anyone knows hoe to get a NSString like "álgeBra" to "Algebra", without the accent, and capitalize only the first letter?
Thanks,
RL
See Question&Answers more detail:osDoes anyone knows hoe to get a NSString like "álgeBra" to "Algebra", without the accent, and capitalize only the first letter?
Thanks,
RL
See Question&Answers more detail:osdreamlax has already mentioned the capitalizedString
method. Instead of doing a lossy conversion to and from NSData
to remove the accented characters, however, I think it is more elegant to use the stringByFoldingWithOptions:locale:
method.
NSString *accentedString = @"álgeBra";
NSString *unaccentedString = [accentedString stringByFoldingWithOptions:NSDiacriticInsensitiveSearch locale:[NSLocale currentLocale]];
NSString *capitalizedString = [unaccentedString capitalizedString];
Depending on the nature of the strings you want to convert, you might want to set a fixed locale (e.g. English) instead of using the user's current locale. That way, you can be sure to get the same results on every machine.