Summary of the NSString method in OC language (all)
// Value of Arrays: (1) storing multiple elements (2) storage elements can only be objects and objects can be of different types. (3) array is an Ordered Set * (4) elements in the array can be repeated and repeated objects will become array elements. // 1 create an array object // (1) Use the constructor // nil as the ending sign for storing array elements. elements after nil are encountered are not put into the element; NSArray * arr1 = [NSArray arrayWithObjects: @ "5", @ "bb", @ "cc", @ "dd ", @ "ee", @ "ff", nil]; NSLog (@ "% @", arr1); NSArray * arr2 = [[NSArray alloc] initWithObjects: @ "5 ", @ "bb", @ "cc", @ "dd", @ "ee", @ "ff", @ "dd", @ "5", @ "bb ", @ "cc", @ "dd", @ "ee", @ "ff", @ "dd", nil]; NSLog (@ "% @", arr2 ); // (2) use the initialization method // 2. obtain the number of elements NSUInteger count = [arr1 count]; NSLog (@ "% lu", count); // 3. obtain the object based on the index value // (1) obtain the element NSString * str = [arr2 objectAtIndex: 0]; NSLog (@ "% @", str ); // (2) obtain the first element in the element // The firstObject and objectAtIndex: 0 Methods: Fortunately, when the array element is empty, nil is returned, while objectAtIndex: 0 will cause the program crash. index 0 beyond bound of empty array. array subscript out of bounds. NSString * str2 = [arr2 firstObject]; NSString * str3 = [arr2 lastObject]; NSLog (@ "% @", str2); NSLog (@ "% @", str3 ); // (3) obtain the second element in the array // 4. obtain the index value of the object in the array NSUInteger index = [arr2 indexOfObject: @ "dd"]; NSLog (@ "% lu", index); // 5. determines whether an object BOOL isExist = [arr2 containsObject: @ "dd"]; NSLog (@ "% d", isExist); // 6. array sorting (Children's edition) NSArray * sortArr = [arr2 sortedArrayUsingSelector: @ selector (compare :)]; NSLog (@ "% @", sortArr); // 7. fast traversal (quick enumeration) // for (int I = 0; I <[arr2 count]; I ++) {// NSString * str = [arr2 objectAtIndex: I]; /// NSLog (@ "% @", str); //}/*** forin fast enumeration (fast traversal) is used to traverse the elements in the set, type * object // The type of the element in the type array. // name of an object (set by yourself) collection: collection (that is, a large container, array, Dictionary, or set) // * // for (NSString * str in arr2) {// NSLog (@ "% @", str );//}