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