Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Lauchlan

macrumors newbie
Original poster
Jul 15, 2012
2
0
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.
Code:
- (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 "-"
 
Last edited by a moderator:
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?
 
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.