Example Nsdictionary Programming Questions-Dictionary sorting application (IOS4 Class)

Source: Internet
Author: User

Code:

#import<Foundation/Foundation.h>intMainintargcConst 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 *time=@"2015-09-01 08:19:10"; NSString*str1=[time Substringfromindex: One ]; Nsrange rang={ One,8}; NSString*str2=[Time Substringwithrange:rang]; NSLog (@"index:%@,range:%@", STR1,STR2); /*2. Access the following data in the array: @[@{@ "name": @ "Chenfong", @ "age": @ "+"}, @{@ "name": @ "Sun Ming", @ "age": @ "@"}, @{@ "name": @ "Wang Ming" @ "Age": @ "@{@"}, "name": @ "Lisiek", @ "ages": @ "50"}] 1) sort (descending), output data 2) Delete "Chenfong" and output data */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":@" -"}; Nsarray*arr=[Nsarray Arraywithobjects:dic1,dic2,dic3,dic4,nil]; Nssortdescriptor*disc=[[nssortdescriptor Alloc]initwithkey:@" Age"Ascending:no]; Nsarray*elesort=[Nsarray Arraywithobjects:disc,nil]; Nsarray*arrsort=[arr Sortedarrayusingdescriptors:elesort];  for(Nsdictionary *dicinchArrsort) {NSLog (@"name:%@,age:%@", dic[@"name"],dic[@" Age"]); } Nsmutablearray*mutarr=[Nsmutablearray Arraywitharray:arrsort];  for(intI=0; i<mutarr.count;i++){            if([mutarr[i][@"name"] IsEqual:@"Chenfong"]) {[Mutarr removeobject:mutarr[i]]; }        }             for(Nsdictionary *dic2inchMutarr) {NSLog (@"name:%@,age:%@", dic2[@"name"],dic2[@" Age"]); }    }    return 0;}

Example Nsdictionary Programming Questions-Dictionary sorting application (IOS4 Class)

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.