NSRangeException while using substringWithRange:NSMakeRange

243 views Asked by At

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.

1

There are 1 answers

1
Nico On BEST ANSWER

Try this, you misplace your "]"

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