I have an array, see below,
NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];
Now i want all the string which is right to the character "x" in to another array. That is i need an array with elements @"2",@"3",@"3"
from the above array.
How can i achieve this?? thanks..
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]];
}
NSMutableArray *myArray=[[NSMutableArray alloc]initWithObjects:@"45 x 2",@"76 x 3",@"98 x 3", nil];
NSMutableArray *suffixArray = [NSMutableArray array];
for (NSString *el in myArray)
{
NSRange range = [el rangeOfString:@"x"];
if (range.location == NSNotFound) [prefixArray addObject:@""];
NSString *suffix = [el substringFromIndex:range.location+range.length];
[suffixArray addObject:suffix];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With