Reputation: 655
I would like to transform NSData to int in Objective-c.
In the following code, "index2" is "15", but "value" is "0". (NSLog says "15,0".)
To be exact, "value" must be "15".
NSString *index = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *index2 = [index stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
int value = [index2 intValue];
NSLog(@"%@,%d",index2,value);
Could you tell me how to solve this problem?
Upvotes: 0
Views: 1384