#import <Foundation/Foundation.h>
#define NSLOG (FORMAT, ...) printf ("%s\n", [[NSString Stringwithformat:format, # #__VA_ARGS__] utf8string])
int main (int argc, const char * argv[]) {
@autoreleasepool {
1. For the string "2015-09-01 08:19:10" operation, output "08:19:10". Two methods of interception are required.
nsstring* str [email protected] "2015-09-01 08:19:10";
The first of these methods
nsstring* str1 = [str substringfromindex:11];
NSLog (@ "%@", str1);
The second method of
Nsrange range = Nsmakerange (11, 8);
nsstring* str2 = [str substringwithrange:range];
NSLog (@ "%@", str2);
/*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
*/
nsarray* array = @[@{@ "name": @ "Chenfong" @ "Age": @ "32"},
@{@ "name": @ "Sun Ming" @ "age": @ "24"},
@{@ "name": @ "Wang Ming" @ "age": @ "12"},
@{@ "name": @ "Lisiek" @ "Age": @ "50"}
];
nsarray* array2 = [array sortedarrayusingcomparator:^nscomparisonresult (ID obj1, id obj2) {
int object1 = [obj1[@ "Age"]intvalue];
int object2 = [obj2[@ "Age"]intvalue];
if (OBJECT1==OBJECT2)
{
return nsorderedsame;
}
else if (OBJECT1<OBJECT2)
{
return nsordereddescending;
}
Else
{
return nsorderedascending;
}
}];
NSLog (@ "Descending????????????????????????????????????????");
for (id obj in array2)
{
nsdictionary* dic = obj;
NSLog (@ "%@%@", dic[@ "name"],dic[@ "Age"]);
}
nsmutablearray* array3 =[nsmutablearray Arraywitharray:array2];
for (int i =0; i<array3.count;i++)
{
nsdictionary* dic = Array3[i];
if ([dic[@ "name"]isequal:@ "Chenfong"])
{
[Array3 Removeobject:dic];
}
NSLog (@ "%@%@", dic[@ "name"],dic[@ "Age"]);
}
NSLog (@ "????????????????????????????????????????");
for (id obj in array3)
{
nsdictionary* dic = obj;
NSLog (@ "%@%@", dic[@ "name"],dic[@ "Age"]);
}
}
return 0;
}
Delete the array inside the dictionary file, then flashback, delete the specified array element