1.数组与字符间转换
componentsSeparatedByString:将字符串以x分割成数组
componentsJoinedByString:将数组以x拼接为字符串
2.排序
Description:按描述条件("对象”->一般字符对象或对象的属性)排序.
NSString *str = @"123-456-789-000"; NSArray *arr = [str componentsSeparatedByString:@"-"]; NSLog(@"%@",arr); NSString *str2 = [arr componentsJoinedByString:@""];//数组转为字符串 NSLog(@"%@",str2); NSMutableArray *arr2 = [[NSMutableArray alloc]init]; [arr2 addObject:@"1"]; [arr2 insertObject:@"3" atIndex:0]; [arr2 addObject:@"2"]; NSLog(@"%@",arr2); //系统的compara:适合字符串,不适合对象排序 //2 NSSortDescriptor *sort1 = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];//nil或self [arr2 sortUsingDescriptors:[NSArray arrayWithObject:sort1]];//注意可变排序方法和不可排序方法的区别 NSLog(@"%@",arr2); //3复杂对象的排序 Student *s1 = [[Student alloc]init]; s1.name = @"obanma"; Student *s2 = [[Student alloc]init]; s2.name = @"jobs"; Student *s3 = [[Student alloc]init]; s3.name = @"bill"; NSMutableArray *arr3 = [NSMutableArray arrayWithObjects:s1,s2,s3,nil]; NSSortDescriptor *sort2 = [NSSortDescriptor sortDescriptorWithKey:@"name" ascending:YES];//kvc [arr3 sortUsingDescriptors:[NSArray arrayWithObject:sort2]]; for (Student *stu in arr3) { NSLog(@"stu.name = %@",stu.name); }