I am new to iOS. I need to convert textfield integer value into string. I created textfield name as value1
and string as str1
.
str1 = [NSString stringWithFormat:@"%d", value1];
I am new to iOS. I need to convert textfield integer value into string. I created textfield name as value1
and string as str1
.
str1 = [NSString stringWithFormat:@"%d", value1];
By default, UITextField
returns a NSString
value.
So you can get any value like this :
NSString *str1 = value1.text;
As simple as that, but if you want to convert it to
Int
then,
int strInt = str1.intValue;
NSInteger strInteger = str1.integerValue;
If want to converts to a
Double
value,
double strDouble = str1.doubleValue;
CGFloat strCGFloat = str1.doubleValue;
And yes, if you don't need to perform anything on
str1
then you shouldn't need to create an instance, you can directly convert it like this.
int strInt = value1.text.intValue;
NSInteger strInteger = value1.text.intValue;