Reputation: 909
I have a string like this
12,23,45,3,12,
What I want to do is get this each number and check with an array value. How I can get each value as a substring to check
Thanks
Upvotes: 1
Views: 76
Reputation: 46543
Break this string to array.
NSString *string = @"12,23,45,3,12,";
NSArray *array = [string componentsSeparatedByString:@","];
Then you can compare with the array.
EDIT :
As per your comment that you want to check all the string values to be present in main-other-array.
NSString *string = @"12,23,45,3,12";
NSArray *array = [string componentsSeparatedByString:@","];
//below is the main-other-array
NSArray *toCheckArray = @[@"124",@"23",@"45",@"3",@"12",@"1000"];
BOOL arrayIsContainedInToCheckArray = YES;
for (NSString *arrayObj in array) {
if (![toCheckArray containsObject:arrayObj]) {
arrayIsContainedInToCheckArray = NO;
}
}
NSLog(@"%@",arrayIsContainedInToCheckArray?@"All exist":@"All doesn't exist");
Upvotes: 3
Reputation: 17585
Use this, It will help you..
NSArray *detailArray = [yourString componentsSeparatedByString:@","];
Upvotes: 1
Reputation: 19418
May be it helps you :
NSString *str = @"12,23,45,3,12";
NSArray *strArray = [str componentsSeparatedByString:@","];
NSArray * anotherArray = nil; // have some value
for (NSString * value in strArray)
{
int intVal = [value integerValue]; // here is your separate value
for (int i = 0; i < [anotherArray count]; i++) // You can check against another array
{
id anotherVal = [anotherArray objectAtIndex:i];
// Here you can check intVal and anotherVal from another array
}
}
Upvotes: 2