dreamlax 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…