Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the first character in each word of a string to uppercase

I found the function below :

CFStringCapitalize

"Changes the first character in each word of a string to uppercase (if it is a lowercase alphabetical character)."

void CFStringCapitalize (
   CFMutableStringRef theString,
   CFLocaleRef locale
);

Does anyone know how to use it with my NSMutableString ?

Thank you,

Gauthier.

like image 734
gotye Avatar asked Feb 27 '10 15:02

gotye


2 Answers

The capitalizedString method exists in NSString class, see the docs

NSString *foo = @"this is all lower";
NSString *fooUpper = [foo capitalizedString];

Note that this isn't iPhone specific, same code on the Mac.

like image 157
NeilInglis Avatar answered Sep 21 '22 12:09

NeilInglis


(NSString *)capitalizedString

So:

NSString *myString,*myCapitalizedString;

myString = @"capitalize";
myCapitalizedString = [myString capitalizedString]; //produces a capitalized copy of 'myString'
like image 30
ennuikiller Avatar answered Sep 19 '22 12:09

ennuikiller