0

I'm having an odd error I don't understand. I've looked at other questions, and I see that NSMakeRange is anchor, distance to traverse. This single statement causes a NSRangeException, out of bounds error though:

    if([myCompare characterAtIndex:([myCompare length]-7) == 'N'])
    {
        [myTemp appendString:[myCompare substringWithRange:NSMakeRange(0,([myCompare length]-7))]];
    }

In this case, I don't understand how it could EVER be out of range, since I'm always subtracting 7 from the length of the NSString and making THAT that range.

It might be a stupid error, but I would appreciate another set of eyes to figure out why that is causing my NSRangeException.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • It will be out of range if myCompare is less than 7 characters long. – rdelmar Sep 09 '13 at 19:16
  • Aye, it dawned on me not too long after posting this. I just had to walk away from the keyboard a while. I was in a situation where I was never being passed less than 7, and then suddenly I was. – user2762440 Sep 13 '13 at 14:52

1 Answers1

0

Try this, you misplace your "]"

if([myCompare length] >= 7 && [myCompare characterAtIndex:([myCompare length]-7)] == 'N')
{
}
Nico
  • 513
  • 7
  • 13