iphone - 返回 NSString 首字母大写

标签 iphone objective-c nsstring uisearchbar

我想返回大写的 NSString 的第一个字母。我有一个 UISearchDisplayController,它根据搜索结果的标题显示部分标题。

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *sectionTitle;
    if (searching) 
        sectionTitle = [searchSectionTitles objectAtIndex:section];
    else
        sectionTitle = [[collation sectionTitles] objectAtIndex:section];

    return sectionTitle;

}

然后在我的搜索功能中返回字母

[searchSectionTitles addObject:[lastName firstLetter]];

我该怎么做

- (NSString *)firstLetter

返回 NSString 的第一个字母?

最佳答案

下面的代码将字符串的首字母大写,在这种情况下首字母大写的字符串称为sectionTitle

NSString *firstLetter = [[sectionTitle substringToIndex:1];

firstLetter = [firstLetter uppercaseString];

关于iphone - 返回 NSString 首字母大写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11894738/

相关文章:

objective-c - 如何将私有(private)框架添加到项目中?

ios - 使用 NSRange 获取子字符串

ios - 在 Swift 中匹配独立的子字符串

objective-c - 范围超出范围的子字符串?

iphone - 带有动画启动画面的iPhone/iPad应用

html - iPhone 不会尊重大于 ~1000 的元视口(viewport)。任何超过 1000 的值都被视为 ~1000! :(

ios - 在 IOS 中为框架创建 bundle ?

iphone - 如何在iphone sdk上将NSData转换为CGDataProviderRef?

objective-c - 为 UITextField 添加前缀

iphone - 使用 UITapGestureRecognizer 根据 iPhone 中的手指触摸位置添加新 View