zoukankan      html  css  js  c++  java
  • objective-c对NSArray的学习

    转自:http://gekie.iteye.com/blog/1086256

    NSARRAY简单的使用

    定义数组,遍历数组:

    1
    2
    3
    4
    5
    6
    7
    8
    
        NSArray *array;
        array = [NSArray arrayWithObjects:@"one", @"two", @"three", @"four",nil];
     
        int i;
        for(i = 0; i < [array count]; i++)
        {
            NSLog(@"index %d has %@.",i,[array objectAtIndex:i]);
        }

    切分字符串:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    
        NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
     
        // insert code here...
        NSString *string = @"oop:ack:bork:greeble:ponies";
     
        NSArray *array = [[[NSArray array] init] autorelease];
    //    array = [NSArray arrayWithObjects:@"one", @"two", @"three", @"four",nil];
     
        array = [string componentsSeparatedByString:@":"];
     
        int i;
        for(i = 0; i < [array count]; i++)
        {
            NSLog(@"index %d has %@.",i,[array objectAtIndex:i]);
        }

    合并数组:

    1
    2
    
    NSArray  *array1 = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
    NSString *joinedString = [array1 componentsJoinedByString:@","];

    可变数组:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
        NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
     
        array = [NSMutableArray arrayWithCapacity: 17];
     
        int i;
     
        for(i = 0; i < 4; i++)
        {
            [array addObject:@"aaa"];
            NSLog(@"hello %d  %@",i, [array objectAtIndex:i]);
        }
     
  • 相关阅读:
    C# 串口调试助手源码
    C# 中 textBox 侧面滑条 属性
    C# 中 comboBox 禁止输入
    VS2015 下载 破解
    中国移动OnetNet云平台 GET指令使用
    JSON JsonArray和JsonObject学习资料
    sublime 添加 ConvertToUTF-8
    sublime 添加 颜色插件 colorcoder
    线程池
    爬虫中基本的多线程
  • 原文地址:https://www.cnblogs.com/wangpei/p/3202176.html
Copyright © 2011-2022 走看看