Podciąg z zakresem poza zakresem?

Dobrze, więc jest to trochę mylące (dobrze dla mnie). Mam ciąg, który ma z niego pojedynczy numer. Otoczyłem ten numer znakiem „/”, dzięki czemu będę mógł później uzyskać ten numer.

Oto jak otrzymuję z tego numer:

if ([MYSTRING hasSuffix:@"mp"]) {
        int start = 0;
        int end = 0;
        char looking = '/';
        for(int i=0; i < MYSTRING.length; i++){
            if (looking == [MYSTRING characterAtIndex:i]) {
                if (start == 0) {
                    start = i;
                }
                else{
                    end = i + 1;
                }
            }
        }
        NSLog(@"%@", MYSTRING); //When i NSLOG here i get '2012-06-21 03:58:00 +0000/1/mp', 1 is the number i want out of the string, but this number could also change to 55 or whatever the user has
        NSLog(@"start: %i, end: %i", start, end); //When i NSLOG here i get 'start: 25, end: 28'
        NSString *number = [MYSTRING substringWithRange:NSMakeRange(start, end)];
        number = [number stringByReplacingOccurrencesOfString:@"/" withString:@""];
        if ([number intValue] > numberInt) {
            numberInt = [number intValue];
        }

Ciągle się zawiesza, a konsola mówi:

* Zakończenie aplikacji z powodu nie przechwyconego wyjątku „NSRangeException”, powód: „- [__ NSCFString substringWithRange:]: Zakres lub indeks poza zakresem” * Pierwsze połączenie rzut stos (0x1875d72 0x106ce51 0x1875b4b 0x184ea64 0x3a6c 0x1080713 0x1bf59 0x1bef1 0xd532e 0xd588c 0xd49f5 0x49a2f 0x49c42 0x290fe 0x1b3fd 0x17d2f39 0x17d2c10 0x17ebda5 0x17ebb12 0x181cb46 0x181bed4 0x181bdab 0x17d1923 0x17d17a8 0x18e71 0x200d 0x1f35) libc ++ abi.dylib: Kończy nazywane rzuca wyjątek

Z mojego liczenia zasięgu jest w granicach, nie rozumiem dlaczego otrzymuję ten błąd?

Każda pomoc byłaby doceniana.

Dzięki

questionAnswers(4)

yourAnswerToTheQuestion