如何在目标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;