I am new to Objective C and am having a odd problem with substringToIndex.
Background:
The code is part of a function that deletes the last character from the display of a calculator. I need to be able to flag when a dot is deleted
My code is:
NSString *currentDisplay = self.display.text;
NSString *lastChar = [currentDisplay substringToIndex: 1];
NSLog(@"lastChar -->%@<--",lastChar);
The problem is:
Variable currentDisplay is a numeric value, for example “123.45”. When the “.” (dot) is the character to be deleted, so variable lastChar is should be “.”, the log shows a random number, normally the last characted deleted.
Any idea what I am doing wrong?
Many Thanks,
Alex
If you want to tell if the last character is a “dot”, use