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

ios练习题--第四期

时间:2016-01-09 13:56:29      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:

1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。

2.数组中存取以下数据:

  @[@{@"name":@"陈丰",@"age":@"32"},

    @{@"name":@"孙明",@"age":@"24"},

    @{@"name":@"王明",@"age":@"12"},

    @{@"name":@"李西",@"age":@"50"}

   ]

     1)按年龄进行排序(降序),输出数据

     2)删除“陈丰”并输出数据

 

#import <Foundation/Foundation.h>

 

int main(int argc, const char * argv[]) {

    @autoreleasepool {


NSString *str=@"2015-09-01 08:19:10"; NSRange range1=[str rangeOfString:@"08:19:10"]; NSString *subStr=[str substringWithRange:range1]; NSLog(@"第一题-------(1)"); NSLog(@"%@",subStr); NSString *substr1=[str substringFromIndex:range1.location]; NSLog(@"第一题-------(2)"); NSLog(@"%@",substr1); NSArray *arr1=@[@{@"name":@"陈丰",@"age":@"32"}, @{@"name":@"孙明",@"age":@"24"}, @{@"name":@"王明",@"age":@"12"}, @{@"name":@"李西",@"age":@"50"} ]; NSDictionary *dic1=@{@"name":@"陈丰",@"age":@"32"}; NSDictionary *dic2=@{@"name":@"孙明",@"age":@"24"}; NSDictionary *dic3=@{@"name":@"王明",@"age":@"12"}; NSDictionary *dic4=@{@"name":@"李西",@"age":@"50"}; NSMutableArray *arr=[[NSMutableArray alloc]initWithObjects:dic1,dic2,dic3,dic4,nil]; NSSortDescriptor *sorts=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:YES]; [arr sortUsingDescriptors:[NSArray arrayWithObjects:sorts, nil]]; NSLog(@"第二题-------(1)"); NSLog(@"排序后-------(升序)"); for(NSDictionary *dic in arr){ NSLog(@"%@ %@",dic[@"name"],dic[@"age"]); } NSLog(@"排序后-------(降序)"); NSSortDescriptor *sorts1=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:NO]; [arr sortUsingDescriptors:[NSArray arrayWithObjects:sorts1, nil]]; for(NSDictionary *dic in arr){ NSLog(@"%@ %@",dic[@"name"],dic[@"age"]); } NSLog(@"第二题-------(2)"); for(int i=0;i<[arr count];i++){ NSDictionary *dic=arr[i]; if([dic[@"name"] isEqual:@"陈丰"]){ [arr removeObject:dic]; } } for(NSDictionary *dic in arr){ NSLog(@"%@ %@",dic[@"name"],dic[@"age"]); }
 }

return 0;

}

ios练习题--第四期

标签:

原文地址:http://www.cnblogs.com/jun1994/p/5116216.html

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