views:

65

answers:

1

Hi,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());
+2  A: 
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..

Larsaronen
You actually don't need to trim the white space, since integerValue skips it anyway. And to return an int, you should use -intValue
JeremyP