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

iOS学习路之Objective-C(三)—— NSMutableString

时间:2015-05-11 19:48:05      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:

  1. NSMutableString可变字符串的创建

    1     NSMutableString *string1 = [[NSMutableString alloc] init];
    2     //string2对象方法由创建,string3由类方法创建
    3     NSMutableString *string2 = [[NSMutableString alloc] initWithCapacity:0];
    4     NSMutableString *string3 = [NSMutableString stringWithCapacity:0];

     

  2. 字符串的添加

    1     NSMutableString *string = [[NSMutableString alloc] init];
    2     //- (void)appendString:(NSString *)aString;
    3     //作用:在字符串后添加,不用创建新的字符串
    4     [string appendString:@"bei jing ying nin"];
    5     NSLog(@"%@", string);
    6     //- (void)insertString:(NSString *)aString atIndex:(NSUInteger)loc;
    7     //作用:在字符串某位置插入字符串
    8     [string insertString:@"huan" atIndex:8];
    9     NSLog(@"%@", string);

     

  3. 字符串的删除

        NSMutableString *string = [[NSMutableString alloc] init];
        [string appendString:@"bei jing huan ying nin"];
        NSLog(@"%@", string);
        //- (void)deleteCharactersInRange:(NSRange)range;
        //作用:字符串的删除
        NSRange range = {1, 5};
        [string deleteCharactersInRange:range];
        NSLog(@"%@", string);

     

iOS学习路之Objective-C(三)—— NSMutableString

标签:

原文地址:http://www.cnblogs.com/dyikai/p/4495350.html

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