码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 改变字母的大小写

时间:2014-08-27 00:28:16      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:blog   http   os   使用   io   strong   ar   2014   cti   

使用 lowercaseString,uppercaseString

- (void)test{
    NSString *testString = @"Hello World";
    
    // lower case
    NSString *lowerCaseString1 = [testString lowercaseString];
    NSString *lowerCaseString2 = testString.lowercaseString;
    
    // upper case
    NSString *upperCaseString1 = [lowerCaseString1 uppercaseString];
    NSString *upperCaseString2 = lowerCaseString1.uppercaseString;
    
    NSLog(@"lowerCaseString1: %@",lowerCaseString1);
    NSLog(@"lowerCaseString2: %@",lowerCaseString2);
    NSLog(@"upperCaseString1: %@",upperCaseString1);
    NSLog(@"upperCaseString2: %@",upperCaseString2);
    
    // capitalize the first word of the sentence
    NSString *txt = @"hi my friends!";
    txt = [txt stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[txt substringToIndex:1] uppercaseString]];
    NSLog(@"txt: %@", txt);
}

打印结果:

2014-08-26 17:00:30.266 MyApp[68821:60b] lowerCaseString1: hello world
2014-08-26 17:00:30.267 MyApp[68821:60b] lowerCaseString2: hello world
2014-08-26 17:00:30.267 MyApp[68821:60b] upperCaseString1: HELLO WORLD
2014-08-26 17:00:30.267 MyApp[68821:60b] upperCaseString2: HELLO WORLD
2014-08-26 17:00:30.268 MyApp[68821:60b] txt: Hi my friends!

参考来源:

http://stackoverflow.com/questions/8693741/converting-all-text-to-lower-case-in-objective-c

http://stackoverflow.com/questions/2432452/how-to-capitalize-the-first-word-of-the-sentence-in-objective-c

iOS 改变字母的大小写

标签:blog   http   os   使用   io   strong   ar   2014   cti   

原文地址:http://blog.csdn.net/willyang519/article/details/38855971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!