About the flashback, descending order of the array, whether the directory contains files, Chinese sort, etc.

Source: Internet
Author: User

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";

NSLog (@ "The first question");

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 *str=[nsstring stringwithformat:@ "%@, age%@ years, subjects%@, score%@", dic[@ "name"],dic[@ "ages"],dic[@ "subject"],dic[@ " Score "];

NSLog (@ "%@", str);

}

NSNumber *[email protected];

NSNumber *[email protected];

NSNumber *[email protected];

NSNumber *[email protected];

NSNumber *[email protected];

Nsarray *brr=[nsarray arraywithobjects:a,b,c,d,e, nil];

NSLog (@ "second question");

2nd question: 12,9,34,56,11 deposit Nsarray Array, output: 1) Reverse output 2) descending output

NSLog (@ "Reverse output method one");

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

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

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

}

NSLog (@ "Reverse output Method II");

nsarray* REVERSEDARRAY=[[BRR reverseobjectenumerator]allobjects];

For (ID str2 in Reversedarray)

{

NSLog (@ "%@", str2);

}

NSLog (@ "descending sort");

Nscomparator comp=^ (ID obj1,id obj2) {

Nscomparisonresult Result=[obj2 Compare:obj1];

return result;

};

Nsarray *sortedarr=[arr1 Sortedarrayusingcomparator:comp];

For (ID i in Sortedarr) {

NSLog (@ "%@", I);

}

NSLog (@ "3rd" to determine whether the intermediate directory exists ");

/* 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 rang1=[str rangeofstring:@ "Qianfeng"];

if (rang1.location==nsnotfound) {

NSLog (@ "not found");

}

else{

NSLog (@ "found at Loacation:%ld", rang1.location);

}

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

if (rang2.location==nsnotfound) {

NSLog (@ "not found");

}

else{

NSLog (@ "found at Loacation:%ld", rang2.location);

}

NSLog (@ "4th" array of elements in Chinese sort);

/* The elements in the array 4th sorted by Chinese

*/

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

Nsarray *sortedarr2=[arr sortedarrayusingselector: @selector (localizedcompare:)];

For (NSString *str in sortedArr2) {

NSLog (@ "%@", str);

}

return 0;

}

About the flashback, descending order of the array, whether the directory contains files, Chinese sort, etc.

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.