title: Substring with range out of bounds?
body: <p>Okay, so this is a bit confusing (well to me). I have a string that has a single number I want out of it. I have surrounded this number with '/' so that I will be able to get that number out of it later.</p>
  
  <p>Here is how I am getting the number out of it:</p>
  
  <pre><code>if ([MYSTRING hasSuffix:@"mp"]) {
          int start = 0;
          int end = 0;
          char looking = '/';
          for(int i=0; i &lt; 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] &gt; numberInt) {
              numberInt = [number intValue];
          }
  </code></pre>
  
  <p>It keeps crashing and the console says: </p>
  
  <blockquote>
    <p><strong>* Terminating app due to uncaught exception 'NSRangeException', reason: '-[__NSCFString substringWithRange:]: Range or index out of bounds'
    *</strong> First throw call stack:
    (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: terminate called throwing an exception</p>
  </blockquote>
  
  <p>From my counting the range is within the bounds, I dont get why I am getting this error?</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks</p>