I’m trying to figure out why this code doesn’t work. I’m trying to search if a string contains “|P”. If it does, I want to do something.
NSMutableArray *list = [pView getPOIList];
NSString *cellValue = [list objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
NSArray *chunks = [cellValue componentsSeparatedByString: @"|P"];
//NSLog([[chunks count] stringValue]);
if([&chunks[1] isEqualToString:@"|P"]) {
//Do Something
}
This makes my app crash.
NSArray *chunksis a NSArray, not a C array. You can use[chunks objectAtIndex:1]to find the object instead of&chunks[1].To find if an sting contains an other string, you can use
([cellValue rangeOfString:@"IP"].length == 0). If the length of the range is 0, then the string doesn’t exist in the original string. Reference