標籤:
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)刪除“陳豐”並輸出資料
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 *[email protected][@{@"name":@"陳豐",@"age":@"32"}, @{@"name":@"孫明",@"age":@"24"}, @{@"name":@"王明",@"age":@"12"}, @{@"name":@"李西",@"age":@"50"} ]; NSDictionary *[email protected]{@"name":@"陳豐",@"age":@"32"}; NSDictionary *[email protected]{@"name":@"孫明",@"age":@"24"}; NSDictionary *[email protected]{@"name":@"王明",@"age":@"12"}; NSDictionary *[email protected]{@"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"]); }
iOS 第四期考核題