PDA

View Full Version : deleteCharactersInRange Help




Lauchlan
Jul 15, 2012, 04:33 PM
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 "-"



chown33
Jul 15, 2012, 04:58 PM
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?

Lauchlan
Jul 16, 2012, 02:43 AM
no complier error. it just won't remove the minus sign !

itickings
Jul 16, 2012, 06:19 AM
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.