#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
@autoreleasepool {
//1.对字符串“2015-09-01 08:19:10”操作,输出"08:19:10"。要求使用两种截取方式。
NSString *str1=@"2015-09-01 08:19:10";
NSString *newstr1=[str1 substringFromIndex:11];
NSLog(@"%@",newstr1);
NSRange rang;
rang.location=11;
rang.length=8;
NSString *newStr2=[str1 substringWithRange:rang];
NSLog(@"%@",newStr2);
/*2.数组中存取以下数据:
@[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}
]
1)按年龄进行排序(降序),输出数据
2)删除“陈丰”并输出数据
*/
NSArray *array = @[@{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}];
NSSortDescriptor *ageWithSort=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:NO];
NSArray *elementarr=[NSArray arrayWithObject:ageWithSort];
NSArray *sortArray=[array sortedArrayUsingDescriptors:elementarr];
for (NSDictionary *dic in sortArray) {
NSLog(@"姓名:%@,年龄:%@",dic[@"name"],dic[@"age"]);
}
//删除
NSLog(@" ");
NSMutableArray *muarr=[NSMutableArray array];
for (int i=0; i<sortArray.count; i++) {
NSDictionary *dic=sortArray[i];
if ( ![ [dic objectForKey:@"name"] isEqual:@"陈丰"]) {
[muarr addObject:dic];
}
}
for (NSDictionary *dic in muarr) {
NSLog(@"姓名:%@,年龄:%@",dic[@"name"],dic[@"age"]);
}
}
return 0;
}