Practice string into a dictionary array in descending order the string directory does not exist array Chinese sort

Source: Internet
Author: User

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[]) {

@autoreleasepool {

/* 1th Please store the following data in a dictionary and output the dictionary content as a string output: "xxx, age xxx, subject xxx, score xxx" (replace XXX with the corresponding data).

*/

NSString *name = @ "Zhang San";

Nsinteger age = 22;

NSNumber *[email protected];

NSString *subject = @ "Mathematics";

Nsdictionary *[email protected]{@ "name": Name,

@ ' age ': @ (age),

@ "Score": Score,

@ "Subject": Subject

};

NSString *str1=[nsstring stringwithformat:@ "%@ age%@ account%@ score%@", dic[@ "name"],dic[@ "ages"],dic[@ "score"],dic[@ "subject "]];

NSLog (@ "%@", str1);

NSLog (@ "%@ age%@ account%@ score%@", dic[@ "name"],dic[@ "ages"],dic[@ "score"],dic[@ "subject"]);

/* Question 2nd: 12,9,34,56,11 into Nsarray array, output: 1) Reverse output 2) descending output */

Nsmutablearray *arr=[@[@12,@9,@34,@56,@11]mutablecopy];

Nsarray *arr1=[arr sortedarrayusingcomparator:^nscomparisonresult (ID obj1, id obj2) {

return [Obj2 compare:obj1];

}];

NSLog (@ "descending output");

For (ID ste in Arr1) {

NSLog (@ "%@", Ste);

}

NSLog (@ "reverse");

for (int i = 0; i<arr.count/2; i++) {

[Arr exchangeobjectatindex:i withobjectatindex:arr.count-1-i];

}

NSLog (@ "%@", ARR);

Reverse Method Two

Nsarray *[email protected][@12,@9,@34,@56,@11];

For (Nsinteger I=[arr3 count]-1;i>=0;i--) {

NSLog (@ "%@", Arr3[i]);

}

/* Question 3rd to determine if the intermediate directory exists

such as passing strings @ "/home/qianfeng/oc.txt" and @ "Qianfeng"

return: YES

Incoming string @ "/usr/qianfeng/oc.txt and @" Fengqian "

return: NO

*/

NSString *[email protected] "/home/qianfeng/oc.txt";

Nsrange ran=[string rangeofstring:@ "Qianfeng"];

if (ran.location==nsnotfound) {

NSLog (@ "NO");

}else{nslog (@ "YES");}

NSString *[email protected] "/usr/qianfeng/oc.txt";

Nsrange rang1=[str rangeofstring:@ "Fengqian"];

if (rang1.location==nsnotfound) {

NSLog (@ "NO");

}

else{

NSLog (@ "YES");

}

4th the elements in the array are sorted by Chinese

Nsarray *[email protected][@ "Light Rain", @ "Ann", @ "small wind", @ "Rongrong", @ "Zhang Tao" @ "Li Wenrong"];

Nsarray *arrr=[arr sortedarrayusingselector: @selector (localizedstandardcompare:)];

For (ID ser in arrr) {

NSLog (@ "%@", Ser);

}

}

return 0;

}

Practice string is stored in the dictionary array in descending order the string directory does not exist in the array Chinese sort

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.