How to make first letter of NSString Capital in iPhone dev

iphone

Solution

You have to do it by hand. This is one of those things that has been built into categories so often by so many people that Apple probably doesn't dare add it as an actual method since it would generate category collisions.

NSString *firstCapChar = [[string substringToIndex:1] capitalizedString];
NSString *cappedString = [string stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:firstCapChar];

There are of course many other solutions using NSMutableString or any other way you like to do it using unichar or whatever.

Problem

I am having a NSString to which I am trimming at the start and end for blank spaces. Now I want to make the first alphabet or letter of the string to appear as capital. Is there any short available or I need to take the first alphabet and convert it to capital on my own. tnx.

Original source