Possible Duplicate:
How to do string conversions in Objective-C?
I am trying to convert a user's guess into an integer. How do I do that?
In C, the atoi() function converts a string to an integer.
In Java, we can use Integer.valueOf() and Integer.parseInt() to convert a string to an integer.
What Is stoi() in C++? In C++, the stoi() function converts a string to an integer value. The function is shorthand for “string to integer,” and C++ programmers use it to parse integers out of strings. The stoi() function is relatively new, as it was only added to the language as of its latest revision (C++11) in 2011.
The stoi() function accepts a string as an argument and converts the string's integer component to an integer type.
This is trivial in Objective-C...
NSString *inputString = @"75";
int value = [inputString intValue];
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With