Delete the array inside the dictionary file, then flashback, delete the specified array element

Source: Internet
Author: User
Tags ming

#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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.