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
#import <Foundation/Foundation.h>
int Main (int argc, const Char * argv[]) {
@autoreleasepool {
NSString *[email protected] "2015-09-01 08:19:10"; Nsrange range1=[str rangeofstring:@ "08:19:10"]; NSString *substr=[str Substringwithrange:range1]; NSLog (@ "The first question--(1)"); NSLog (@ "%@", subStr); NSString *substr1=[str SubstringFromIndex:range1.location]; NSLog (@ "The first question--(2)"); NSLog (@ "%@", SUBSTR1); Nsarray *[email protected][@{@ "name": @ "Chenfong", @ "age": @ "+"}, @{@ "name": @ "Sun Ming" @ "age": @ "24"}, @{@ "name": @ "Wang Ming" @ "age": @ "{"}, @{@ "name": @ "Lisiek" @ "Age": @ "50"} ]; Nsdictionary *[email protected]{@ "name": @ "Chenfong" @ "Age": @ "32"}; Nsdictionary *[email protected]{@ "name": @ "Sun Ming" @ "age": @ "24"}; Nsdictionary *[email protected]{@ "name": @ "Wang Ming" @ "age": @ "12"}; Nsdictionary *[email protected]{@ "name": @ "Lisiek" @ "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 (@ "The second question--(1)"); NSLog (@ "After sorting-(ascending)"); For (Nsdictionary *dic in arr) {NSLog (@ '%@%@ ', dic[@ ' name '],dic[@ ' age ']); } NSLog (@ "after sort-(descending)"); 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 (@ "The second question--(2)"); for (int I=0;i<[arr count];i++) {nsdictionary *dic=arr[i]; if ([dic[@ "name"] isequal:@ "Chenfong"]) {[Arr removeobject:dic]; }} for (Nsdictionary *dic in arr) {NSLog (@ '%@%@ ', dic[@ ' name '],dic[@ ' age ']); }
}
Return 0;
}
iOS exercises--fourth issue