iOS Learning Road of Objective-c (Thu)--nsarray

Source: Internet
Author: User

  1. Create an immutable group Nsarray

    1     //Array members are placed in brackets when the array is created, and when NSLog is printed, the array is placed in parentheses2Nsarray *array = @[@"bei",@"Jing",@"Huan",@"Ying",@"Nin"];3     4 #if05 #pragmaThe Mark object method creates an array6Nsarray *array1 =[[Nsarray alloc] initwitharray:array1];7Nsarray *array2 = [[Nsarray alloc] Initwithobjects:@"bei",@"Jing",@"Huan",@"Ying",@"Nin", nil];8 #endif9     Ten #pragmaThe Mark class method creates an array OneNsarray *array1 =[Nsarray Arraywitharray:array]; ANsarray *array2 = [Nsarray arraywithobjects:@"bei",@"Jing",@"Huan",@"Ying",@"Nin", nil];

  2. Number of array members

    1     //instantiate an Array object2Nsarray *array = @[@"bei",@"Jing",@"Huan",@"Ying",@"Nin"];3     //@property (readonly) Nsuinteger count;4     //function: Gets the number of members in the array5NSLog (@"%lu", [array Count]);

  3. Remove a member from an array

    1     //instantiate an Array object2Nsarray *array = @[@"bei",@"Jing",@"Huan",@"Ying",@"Nin"];3     //-(ID) Objectatindex: (nsuinteger) index;4     //function: Gets the corresponding element in the array according to the subscript5NSLog (@"%@", [array Objectatindex:0]);

  4. Get the corresponding subscript based on the value of the element

    1Nsarray *array = @[@"bei",@"Jing",@"Huan",@"Ying",@"Nin"];2     //-(Nsuinteger) Indexofobject: (ID) anobject;3     //function: Find the first corresponding subscript based on the value of the element4NSLog (@"%lu", [array Indexofobject:@"Huan"]);

  5. Concatenation of string and array elements

    1NSString *string1 =@"Chen$chao$ni$hao$ma";2     //-(Nsarray *) componentsseparatedbystring: (NSString *) separator;3     //Function: Splits a string into a string , and the split string is stored in an array as an element of an array4Nsarray *arrayfromstring1 = [string1 componentsseparatedbystring:@"$"];5     6     //-(NSString *) componentsjoinedbystring: (NSString *) separator;7     //function: The elements in an array are stitched into a string by a string8NSString *stringfromarray1 = [arrayFromString1 componentsjoinedbystring:@" "];9NSLog (@"%@", stringFromArray1);Ten      One     //-(Nsarray *) Componentsseparatedbycharactersinset: (Nscharacterset *) separator ns_available (10_5, 2_0); A     //function: Cut according to the character set -NSString *string2 =@"Chen$chao#[email Protected]&ma"; -Nsarray *arrayfromstring2 = [string2 componentsseparatedbycharactersinset:[nscharacterset Charactersetwithcharactersinstring:@"$#@&"]]; theNSString *stringfromarray2 = [ArrayFromString2 componentsjoinedbystring:@" "]; -NSLog (@"%@", stringFromArray2);

iOS Learning Road of Objective-c (Thu)--nsarray

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.