将字符串每个单词中的第一个字符更改为大写

问题描述:

我找到了以下功能:

CFStringCapitalize

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
);

有没有人知道如何在我的NSMutableString中使用它?

Does anyone know how to use it with my NSMutableString ?

谢谢,

Gauthier。

该方法capitalizedString在NSString类存在,见文档

The capitalizedString method exists in NSString class, see the docs

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

请注意,这不是iPhone特有的,Mac上的代码相同。

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