#define NSLog(FORMAT, ...) printf("%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String])
#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";
NSLog(@"第一种");
NSString *newstr2=[str substringFromIndex:11];
NSLog(@"%@",newstr2);
NSLog(@"第二种");
NSRange rang;
rang.location=11;
rang.length=8;
NSString *newStr3=[str substringWithRange:rang];
NSLog(@"%@",newStr3);
/*2.数组中存取以下数据: */
NSArray *str1=@[ @{@"name":@"陈丰",@"age":@"32"},
@{@"name":@"孙明",@"age":@"24"},
@{@"name":@"王明",@"age":@"12"},
@{@"name":@"李西",@"age":@"50"}
];
//1)按年龄进行排序(降序),输出数据
NSSortDescriptor *ageWithSort=[[NSSortDescriptor alloc]initWithKey:@"age" ascending:NO];
NSArray *newarr=[NSArray arrayWithObject:ageWithSort];
NSArray *sortArray=[str1 sortedArrayUsingDescriptors:newarr];
for (NSDictionary *dic in sortArray) {
NSLog(@"姓名:%@,年龄:%@",dic[@"name"],dic[@"age"]);
}
//2)删除“陈丰”并输出数据
NSMutableArray *muarr=[NSMutableArray array];
for (int i=0; i<sortArray.count; i++) {
NSDictionary *dic1=sortArray[i];
if ( ![ [dic1 objectForKey:@"name"] isEqual:@"陈丰"]) {
[muarr addObject:dic1];
}
}
NSLog(@"删除后数据");
for (NSDictionary *dic1 in muarr) {
NSLog(@"姓名:%@,年龄:%@",dic1[@"name"],dic1[@"age"]);
}
}
return 0;
}