Objective C - Number to String and Grab length inconsistencies -
I am trying to capture a number from a text box entry, convert it to string and take the length of it . (IE: Do some LEN (some integers) on the number).
I am capable of working on it, though there are some discrepancies when the number is 0 or zero.
For example;
- Update (IBAction) {// Inputfield number pad text box is double-input input = [input field.text double value]; // nsnm * c = [nsnumber number repeat: my input]; NSString * myOutput = [c stringValue]; NSLog (@ "start number (number) =% @", c); NSLog (@ "MyOutput (string) =% @", MyOutput); NSLog (@ "MyOutput (length) =% d", ([myOutput length])); }
The conversion works fine for the number for the string. The problem I have is with length, especially when there is no number (or zero) entry.
I have a number pad text box entry that is on XIB in which "text" of 0 (placeholder bus "Enter number here")
When you first entered the text box If you start typing then "text" gets removed and you start with a blank text box.
Issue 1 - When you enter the text box for the first time, there is nothing in the textbox, but my NSLog says the output length is 1 character long.
This is the cause of a problem because there is nothing in the visually text box, but [myOutput length] reports 1 character length.
Issue 2 - When you start entering numbers, everything goes well - but when you start to extract the numbers on that number, where you completely text box If we clean, then it reports the length of 1 character.
If there is nothing in the text box, how can it read 1 character? I think it should be "text" (from the Recognition Inspector) again.
summary.
-
There is a number pad text box entry field. Whenever you update the entry, it calls the IBAP update method.
-
When you enter numbers in the text box for the first time, there is nothing visible in the input field, but the NSLog report length is 1 character long.
-
When you start numbers and then start removing them from one time, you remove all the numbers altogether, this length is 1 Describes the character as long as possible.
In both cases, NSLog 0 should be length reporting, but it never does I try to [myOutput length] - 1 but it gives me strange results .
Any help on this will be great
Thank you.
If there is no text, then myInput
equals 0.0. myOutput
then equals @ "0"
, whose length is 1.
Why not only [inputField.text length]
?
You can do something like this:
NSNumber * number = zero; If ([inputField.text length]> gt; 0) {number = [repeat NSNumber number: [inputField.text doubleValue]]; }
In this way if your number is present then otherwise the number
will be zero
.
Comments
Post a Comment