#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。
NSString *str=@"2015-09-01 08:19:10";
NSString *str1=[str substringFromIndex:11];
NSLog(@"%@",str1);
NSRange str2=NSMakeRange(11, 8);
NSString *str3=[str substringWithRange:str2];
NSLog(@"%@",str3);
/*2.数组中存取以下数据:
@[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}
]
*/
NSArray *arr=@[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}];
//1)按年龄进行排序(降序),输出数据
arr= [arr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
int s=[obj1[@"age"] intValue];
int s1=[obj2[@"age"] intValue];
if (s==s1) {
return NSOrderedSame;
}else if (s>s1){
return NSOrderedDescending;
}else{
return NSOrderedAscending;
}
}];
for(id d in arr){
NSLog(@"%@ %@",d[@"name"],d[@"age"]);
}
//2)删除“陈丰”并输出数据
NSMutableArray *str=[NSMutableArray array];
for(int i=0;i<arr.count;i++){
NSDictionary *idc=arr[i];
if (![[idc objectForKey:@"name"]isEqual:@"陈丰"]) {
[str addObject:idc];
}
}
for(id ser in str){
NSLog(@"%@ %@",ser[@"name"],ser[@"age"]);
}
}
return 0;
}