I am working on a calculator App.
The NSMutablestring
is used for calculation E.g "5-3*8-(-1)/77"
.
But the label can't display endless an NSMutablestring
, so is there have any way to limit NSMutablestring
's length?
(not too long, I want the NSMutablestring
's length to be less than 100).
Asked
Active
Viewed 462 times
-2
-
Presumably entry is made using a `UITextField`, therefore: http://stackoverflow.com/questions/2523501/set-uitextfield-maximum-length – trojanfoe Jul 09 '13 at 10:45
-
possible duplicate of [iPhone SDK: Set Max Character length TextField](http://stackoverflow.com/questions/433337/iphone-sdk-set-max-character-length-textfield) – Max MacLeod Jul 09 '13 at 10:46
2 Answers
1
You can get the first 100 characters of a string as follows:
NSString *first100chars = [myString substringToIndex:100];
However, it sounds like you need to prevent the user from actually entering a string this long, which is a different problem. The comments to your question give examples of other people asking similar questions (e.g. Set the maximum character length of a UITextField), I suggest you check those.