我有一个数组,见下文,
NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];
现在我想要将字符“x”右边的所有字符串放入另一个数组中。那就是我需要一个包含上述数组中的元素 @"2",@"3",@"3"
的数组。
我怎样才能做到这一点?? 谢谢..
最佳答案
NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];
NSMutableArray *tempArray = [NSMutableArray array];
for(NSString *string in myArray)
{
NSArray *array = [string componentsSeparatedByString:@"x"];
if(array.count > 1)
[tempArray addObject:[array objectAtIndex:1]];
}
关于iphone - 来自字符串数组 iPhone 的子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7283064/