deleteCharactersInRange Help

Discussion in 'Mac Programming' started by Lauchlan, Jul 15, 2012.

  1. Lauchlan, Jul 15, 2012
    Last edited by a moderator: Jul 15, 2012

    Lauchlan macrumors newbie

    Jul 15, 2012
    I'm trying to get this code to work. But am at a loss as to why it does not.
    The code does add the neg sign "-" if it's not there. But does not remove it if it's there. Please help as I'm trying to get my head around this as a hobby.
    - (IBAction)NegPlus:(UIButton *)sender {
        NSRange hasNegSing = [self.display.text rangeOfString:@"-"];
        NSString *myDisplay = self.display.text;
        if(hasNegSing.location == NSNotFound){
            myDisplay = [@"-" stringByAppendingString: myDisplay];
            self.display.text = myDisplay;
        else {
            NSLog (@"the mydisplay before = %@", myDisplay);
          deleteCharactersInRange:[myDisplay rangeOfString:@"-"];
            NSLog (@"the mydisplay after = %@", myDisplay);
    no warning it runs but just won't delete the "-"
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    Is deleteCharactersInRange: a method of NSString or of NSMutableString? Which class is your variable?

    Did you get a warning or error when compiling this code? What did it say?
  3. Lauchlan thread starter macrumors newbie

    Jul 15, 2012
    no complier error. it just won't remove the minus sign !
  4. itickings macrumors 6502a


    Apr 14, 2007
    Given the posted code, it is no surprise that the minus sign is not removed. Does it match the code you are compiling?

    Try to answer all of chown33's questions, and you should be off to a very good start.

Share This Page