Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert a string into an integer in objective C? [duplicate]

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?

like image 307
user457303 Avatar asked Sep 24 '10 13:09

user457303


People also ask

Can we convert string to integer in C?

In C, the atoi() function converts a string to an integer.

Can we convert string value into number?

In Java, we can use Integer.valueOf() and Integer.parseInt() to convert a string to an integer.

Can we use stoi in C?

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.

What is stoi function in C?

The stoi() function accepts a string as an argument and converts the string's integer component to an integer type.


1 Answers

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

like image 187
John Wordsworth Avatar answered Oct 21 '22 04:10

John Wordsworth