我想返回大写的 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/