将字符串每个单词中的第一个字符更改为大写 [英] Change the first character in each word of a string to uppercase

查看:272
本文介绍了将字符串每个单词中的第一个字符更改为大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了以下功能:

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.

这篇关于将字符串每个单词中的第一个字符更改为大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆