title: Fatal Exception NSRangeException -[__NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {N, N} out of bounds; string length N
body: <p>I'm getting the following error from the code below and I'm not sure why.</p>
  
  <p><strong>Fatal Exception NSRangeException
  -[__NSCFString replaceOccurrencesOfString:withString:options:range:]: Range {0, 7} out of bounds; string length 6</strong></p>
  
  <p>I wondered if someone could explain ?</p>
  
  <p>Is it just that I need to new NSRange variable to cater for the different string length ?</p>
  
  <pre><code>+(double)removeFormatPrice:(NSString *)strPrice {
  
      NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];
      [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
      NSNumber* number = [currencyFormatter numberFromString:strPrice];
  
      //cater for commas and create double to check against the number put 
      //through the currency formatter
      NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
      NSMutableString *mstring = [NSMutableString stringWithString:strPrice];
      NSRange wholeShebang = NSMakeRange(0, [mstring length]);
  
      [mstring replaceOccurrencesOfString: [formatter groupingSeparator]
                               withString: @""
                                  options: 0
                                    range: wholeShebang];
  
      //if decimal symbol is not a decimal point replace it with a decimal point
      NSString *symbol = [[NSLocale currentLocale] 
                    objectForKey:NSLocaleDecimalSeparator];
      if (![symbol isEqualToString:@"."]) {
          [mstring replaceOccurrencesOfString: symbol
                                   withString: @"."
                                      options: 0
                                        range: wholeShebang]; // ERROR HERE
      }
  
      double newPrice = [mstring doubleValue];
      if (number == nil) {
          return newPrice;
      } else {
          return [number doubleValue];
      }
  }
  </code></pre>