1. For the string "2015-09-01 08:19:10" operation, output "08:19:10". Two methods of interception are required.
2. Access the following data in the array:
@[@{@ "name": @ "Chenfong" @ "Age": @ "32"},
@{@ "name": @ "Sun Ming" @ "age": @ "24"},
@{@ "name": @ "Wang Ming" @ "age": @ "12"},
@{@ "name": @ "Lisiek" @ "Age": @ "50"}
]
1) Sort by age (descending), output data
2) Delete "Chenfong" and output data
NSString *str=@"2015-09-01 08:19:10"; Nsrange Range1=[str rangeofstring:@"08:19:10"]; NSString*substr=[str substringwithrange:range1]; NSLog (@"first question--(1)"); NSLog (@"%@", SUBSTR); NSString*substr1=[str substringFromIndex:range1.location]; NSLog (@"first question--(2)"); NSLog (@"%@", SUBSTR1); Nsarray*[email protected][@{@"name":@"Chenfong",@" Age":@" +"}, @{@"name":@"Sun Ming",@" Age":@" -"}, @{@"name":@"Wang Ming",@" Age":@" A"}, @{@"name":@"Lisiek",@" Age":@" -"} ]; Nsdictionary*[email protected]{@"name":@"Chenfong",@" Age":@" +"}; Nsdictionary*[email protected]{@"name":@"Sun Ming",@" Age":@" -"}; Nsdictionary*[email protected]{@"name":@"Wang Ming",@" Age":@" A"}; Nsdictionary*[email protected]{@"name":@"Lisiek",@" Age":@" -"}; 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 (@"The second question--(1)"); NSLog (@"sort after-(ascending)"); for(Nsdictionary *dicincharr) {NSLog (@"%@ %@", dic[@"name"],dic[@" Age"]); } NSLog (@"sort after-(descending)"); Nssortdescriptor*sorts1=[[nssortdescriptor Alloc]initwithkey:@" Age"Ascending:no]; [Arr Sortusingdescriptors:[nsarray arraywithobjects:sorts1, Nil]]; for(Nsdictionary *dicincharr) {NSLog (@"%@ %@", dic[@"name"],dic[@" Age"]); } NSLog (@"The second question--(2)"); for(intI=0; I<[arr count];i++) {nsdictionary*dic=Arr[i]; if([dic[@"name"] IsEqual:@"Chenfong"]) {[Arr removeobject:dic]; } } for(Nsdictionary *dicincharr) {NSLog (@"%@ %@", dic[@"name"],dic[@" Age"]); }
IOS Fourth Exam Questions