#import <Foundation/Foundation.h>
#import "NSString+InsertString.h"
int main(int argc, const char * argv[]) {
//增删改查
NSString *string1 = @"akjhsdferwolk";
NSRange r = [string1 rangeOfString:@"jh" options:NSBackwardsSearch];
NSString *s = [string1 stringByInsertString:@"**" atIndex:r.location];
NSLog(@"%@", s);
NSString *p1 = @"Hello!Lili.Lili.Lili";
NSLog(@"%@", [p1 stringByReplacingOccOfString:@"Lili" withString:@"haha"]);
/数组
NSArray *array = [[NSArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
for (int i = 0; i < [array count]; i++) {// NSLog(@"%@", [array objectAtIndex:i]);
}
NSArray * array1 = [array arrayByAddingObject:@"ddd"];
for (int i = 0; i < [array1 count]; i++) {
NSLog(@"%@", [array1 objectAtIndex:i]);
}
NSArray *array2 = [[NSArray alloc] initWithObjects:@"111", @"222", @"333", nil];
NSArray *array3 = [array1 arrayByAddingObjectsFromArray:array2];
for (int i = 0; i < [array count]; i++) {
NSLog(@"%@", [array3 objectAtIndex:i]);
}
oc的数组会对每一个对象加1;随着数组的释放而释放
///数组包含/
//29
if ([array3 containsObject:@"111"]) {
NSLog(@"yes");
}else {
NSLog(@"no");
}
///查找每个对象的下标///
//35
NSLog(@"%lu", [array3 indexOfObject:@"ddd"]);
/输出第一个和最后一个元素///
//40.41
NSLog(@"%@", [array3 firstObject]);
NSLog(@"%@", [array3 lastObject]);
///84---94便利构造器//
103---Deprecated不需要的
111---122 可变的Mutable (可变数组来调)
oc数组是指针数组,所以可以是多类型的
/把数字封装和取出/
NSMutableArray *mArray = [[NSMutableArray alloc] initWithObjects:@"aaa", @"bbb", @"ccc", nil];
int a = 100;
NSNumber *numA = [[NSNumber alloc] initWithInt:a];
[mArray addObject:numA];
for (int i = 0; i < [mArray count]; i++) {
NSLog(@"%@", [mArray objectAtIndex:i]);
}
NSNumber *num = [mArray lastObject];
int b = [num intValue];
NSLog(@"%d", b);
/把range封装,取出//
NSRange r = NSMakeRange(3, 5);
NSValue *rValue = [NSValue valueWithRange:r];
[mArray addObject:rValue];
NSValue *rv = [mArray lastObject];
NSRange rr = [rv rangeValue];
NSLog(@"%@", NSStringFromRange(rr));
return 0;
}