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)