Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Objective-C equivalent of Java's parseInt()?

m anew comer to iPhone...before i have developed for Android..Could any one tell me what is the alternate code in objective C..Thanx in advance

Int projectNumber = Integer.parseInt(projectNumber.trim());
like image 604
Talktobijju Avatar asked Sep 08 '10 09:09

Talktobijju


1 Answers

int intProjectNumber = [[projectNumber stringByTrimmingCharactersInSet:whitespaceCharacterSet] integerValue];

edit: Just to explain a bit more..

If you have a NSString named projectNumber (ie. @" 4 "). You can make a new string with trimed whitespace infront of the string and after the string with

NSString *trimedProjectNumber = [projectNumber stringByTrimmingCharactersInSet:whitespaceCharacterSet];

as you can see this replaces the trim() function

trimedProjectNumber would now be @"4". If you want an integer representation of this string you do:

int intProjectNumber = [trimedProjectNumber integerValue];

this replaces the parseInt..

I dont know java but i think this is what youre code does? If not explain what the java code does..

like image 56
LarsJK Avatar answered Oct 19 '22 13:10

LarsJK