本文介绍了如何大写Objective-C中句子的第一个单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经找到了如何大写字句的所有字词,但不是第一个字。 txt = @hi my friends!
[txt capitalisedString];
我不想改为小写,大写第一个字符。
解决方案
这里是另一回事:
NSString * txt = @hi my friends!
txt = [txt stringByReplacingCharactersInRange:NSMakeRange(0,1)withString:[[txt substringToIndex:1] uppercaseString]];
对于Swift语言:
txt.replaceRange(txt.startIndex ... txt.startIndex,with:String(txt [txt.startIndex])。capitalizedString)
I've already found how to capitalize all words of the sentence, but not the first word only.
NSString *txt =@"hi my friends!"
[txt capitalizedString];
I don't want to change to lower case and capitalize the first char. I'd like to capitalize the first word only without change the others.
解决方案
Here is another go at it:
NSString *txt = @"hi my friends!";
txt = [txt stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[txt substringToIndex:1] uppercaseString]];
For Swift language:
txt.replaceRange(txt.startIndex...txt.startIndex, with: String(txt[txt.startIndex]).capitalizedString)
这篇关于如何大写Objective-C中句子的第一个单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!