[英]how to convert uitextfield integer into string
I am new to iOS. 我是iOS新手。 I need to convert textfield integer value into string. 我需要将textfield整数值转换为字符串。 I created textfield name as value1
and string as str1
. 我将文本字段名称创建为value1
并将字符串创建为str1
。
str1 = [NSString stringWithFormat:@"%d", value1];
By default, UITextField
returns a NSString
value. 默认情况下, UITextField
返回一个NSString
值。
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
,
int strInt = str1.intValue;
NSInteger strInteger = str1.integerValue;
If want to converts to a
Double
value, 如果要转换为Double
值,
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. 是的,如果您不需要在str1
上执行任何操作,则无需创建实例,可以像这样直接将其转换。
int strInt = value1.text.intValue;
NSInteger strInteger = value1.text.intValue;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.