关于OC基础之数组和字符串的操作

关于OC基础之数组和字符串的操作;

这里我也是初学一下,就是经常用到的方法,我实地测试了下,给大家分享下哦

#import <Foundation/Foundation.h>

intmain (int argc, constchar *argv[])

{

   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];  

       NSMutableArray *p= [[NSMutableArray alloc] initWithObjects:@"3",@"5",@"4",@"1",nil];

   NSMutableArray *pp = [[NSMutableArray alloc] initWithObjects:@"hello",@"hello5",@"hello4",@"heloo1",nil];

   int a =[[p objectAtIndex:1] intValue];

   NSLog(@"a = %d,leg = %d",a,[pcount]);

   int len =[p count];

   NSLog(@"len = %d",len);

   int i =0;

   int j =0;

   //下面是OC的冒泡排序

   for (i =0; i<len; i++)

   {

       for (j=i+1; j<len; j++)

       {

            inta = [[p objectAtIndex:i] intValue];

            intb = [[p objectAtIndex:j] intValue];

            if(a > b)

            {

                [p replaceObjectAtIndex:iwithObject:[NSString stringWithFormat:@"%d",b]];

                [p replaceObjectAtIndex:jwithObject:[NSString stringWithFormat:@"%d",a]];

            }

           

       }

     

   }

   int bb =0;

   NSMutableArray *mArr = [NSMutableArray array];

   for(bb =0; bb<4; bb++)

   {

     [mArr addObject:[pobjectAtIndex:bb]];

     NSLog(@"%@",[pobjectAtIndex:bb]);

   }

   

   int ss =0;

   for (ss=0;ss<4;ss++) {

       NSLog(@"2遍历array:%zd-->%@",ss,[mArrobjectAtIndex:ss]);

       NSString *stddss =[mArr objectAtIndex:ss];

       NSMutableString *str11 = [[NSMutableString alloc] initWithString:nil];

       [str11 appendString:stddss];

       NSLog(@"%@",str11);

   }

   NSLog(@"---------------");

   

   int aa =0;

   NSMutableArray *temp = [NSMutableArray array];

   NSString *str =@"";

   NSMutableString *str1 = [[NSMutableString alloc] initWithString:nil];

   for (aa =0; aa<4; aa++)

   {

     NSLog(@"helliiii");

       NSString *stdd = [pobjectAtIndex:aa];

       [str1 appendString:stdd];

       NSLog(@"%@",[ppobjectAtIndex:aa]);

   }

   NSLog(@"%@",str1);

 

   [pool drain];

   return 0;

}

 

对字符串和数组的操作还有很多方法,大家可以尝试下,我觉的上面的在做项目的话是比较常用的,就写一下,

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值