NSString *str1 = @"文艺青年";
NSMutableString *str2 = [NSMutableString stringWithString:@"文艺青年"];
NSLog(@"%@", [str1 stringByReplacingCharactersInRange:NSMakeRange(0, 2) withString:@"213"]);
[str2 replaceCharactersInRange:NSMakeRange(0, 2) withString:@"213"];
NSLog(@"%@", str2);
NSLog(@"%@", [str1 stringByReplacingOccurrencesOfString:@"文艺" withString:@"213"]);
[str2 setString:@"213青年"];
NSLog(@"%@", str2);
NSMutableString *str3 = [NSMutableString stringWithString:[str1 substringFromIndex:2]];
NSMutableString *str4 = [NSMutableString stringWithString:[str1 substringWithRange:NSMakeRange(2, 2)]];
NSLog(@"%@", str3);
[str4 insertString:@"213" atIndex:0];
NSLog(@"%@", str4);
NSInteger num = 123;
NSString *str0 = [NSString stringWithFormat:@"%ld", num];
NSLog(@"%@", str0);
NSString *str5 = @"i love You";
NSLog(@"%@", str5.capitalizedString);
NSLog(@"%@", [str5.capitalizedString stringByReplacingCharactersInRange:NSMakeRange(2, 1) withString:@"l"]);
NSLog(@"%@", [str5.capitalizedString stringByReplacingOccurrencesOfString:@"L" withString:@"l"]);
NSMutableString *str = [NSMutableString stringWithString:@"20|http: //www.baidu.com"];
NSLog(@"%@", [str componentsSeparatedByString:@"|"]);
NSArray *arr1 = [str componentsSeparatedByString:@"|"];
NSLog(@"%@",[arr1 objectAtIndex:0]);
NSLog(@"%@",[arr1 objectAtIndex:1]);
int a = 1;
float b = 1.1;
double c = 1.11;
BOOL d = 0;
NSRange range = {0,1};
NSNumber *number1 = [NSNumber numberWithInt:a];
NSNumber *number2 = [NSNumber numberWithFloat:b];
NSNumber *number3 = [NSNumber numberWithDouble:c];
NSNumber *number4 = [NSNumber numberWithBool:d];
NSValue *value = [NSValue valueWithRange:range];
NSMutableArray *arr = [NSMutableArray arrayWithObjects:number1, number2, number3, number4, value, nil];
for (NSInteger i = 0; i < arr.count; i++) {
NSLog(@"%@", arr[i]);
NSLog(@"%@", [arr objectAtIndex:i]);
}
Contact *p1 = [[Contact alloc] initWithName:@"ShiChuanYang" number:@"13945873691" sex:@"男" address:@"呼玛县" groupName:@"朋友" age:25];
Contact *p2 = [[Contact alloc] initWithName:@"WangJunMin" number:@"13245678903" sex:@"男" address:@"鹤岗市" groupName:@"朋友" age:23];
Contact *p3 = [[Contact alloc] initWithName:@"WangErMaZi" number:@"13222222597" sex:@"男" address:@"浩良河" groupName:@"陌生人" age:28];
Contact *p4 = [[Contact alloc] initWithName:@"FanCong" number:@"13945870377" sex:@"男" address:@"甘肃省" groupName:@"黑名单" age:24];
Contact *p5 = [[Contact alloc] initWithName:@"LiMuRan" number:@"13945117673" sex:@"女" address:@"宁夏" groupName:@"朋友" age:24];
NSMutableArray *arr = [NSMutableArray arrayWithObjects:p1,p2,p3,p4, nil];
if ([p5.name isEqual:@""] || [p5.number isEqual:@""]) {
NSLog(@"添加失败");
} else {
[arr addObject:p5];
for (Contact *temp in arr) {
[temp sayHi];
}
}
NSLog(@"**********");
for (Contact *temp in arr) {
if ([temp.groupName isEqual: @"朋友"]) {
[temp sayHi];
}
}
NSLog(@"**********");
for (Contact *temp in arr) {
if ([temp.number isEqual: @"13945117673"]) {
[temp sayHi];
}
}
NSLog(@"**********");
for (Contact *temp in arr) {
if ([temp.sex isEqual: @"女"]) {
[temp sayHi];
}
}
NSLog(@"**********");
for (Contact *temp in arr) {
if ([temp.name isEqual: @"FanCong"]) {
[arr removeObject:temp];
break;
}
}
for (Contact *temp in arr) {
[temp sayHi];
}
NSLog(@"**********");
for (Contact *temp in arr) {
if ([temp.groupName isEqual:@"陌生人"]) {
[arr removeObject:temp];
break;
}
}
for (Contact *temp in arr) {
[temp sayHi];
}