将 NSString 转为整数
对不起各位,我是菜鸟。我知道有些语言支持类型转换,但是当我尝试在这里这样做时,它失败了,悲惨地失败了。我有一个只有数字垫的 UITextField,所以我只获取数字,并且我需要 int、diff 中的输出。这是我尝试过的:
NSString *outputNumber = [NSString stringWithFormat:@"%d", [textBox.text]];
diff = [outputNumber intValue]; //Not so much
发生的情况是我的差异达到了一些令人难以置信的高数字,而不是我测试的单个数字。我能得到的任何帮助都很棒。谢谢 :)
Sorry guys, I'm a noob. I know that some languages support type casting, but when I tried to do that here it failed, miserably. I've got an UITextField with number only pad, so I'm only getting numbers, and I need the output from that in my int, diff. Here's what I tried:
NSString *outputNumber = [NSString stringWithFormat:@"%d", [textBox.text]];
diff = [outputNumber intValue]; //Not so much
What happens is my diff goes to some incredibly high number instead of the single digets I tested with. Any help I could get is great. Thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么在 textBox.text 周围使用 [ ]?而且您不需要临时的 outputNumber string 。
试试这个:
Why are you using [ ] around textBox.text? And you dont need temporary outputNumber string .
Try this :