如何在目标C中将字符串转换为整数? [英] How do I convert a string into an integer in objective C?

查看:115
本文介绍了如何在目标C中将字符串转换为整数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在Objective-C中进行字符串转换?

我试图将用户的猜测转换为整数。我该怎么做?

I am trying to convert a user's guess into an integer. How do I do that?

推荐答案

这在Objective-C中是微不足道的......

This is trivial in Objective-C...

NSString *inputString = @"75";
int value = [inputString intValue];

您还可以使用floatValue,doubleValue或(我相信)甚至boolValue将NSString转换为其他类型。这是一个页面,其中列出了您可能需要使用字符串执行的一些常见任务;

You can also use floatValue, doubleValue or (I believe) even boolValue to convert an NSString to other types. Here is a page that lists some common tasks you may need to perform with strings;

http://borkware.com/quickies/one?topic=NSString

这篇关于如何在目标C中将字符串转换为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆