开发者

subtract NSString

I have a line

bookval_int_curr = [str1 intValue] - [str2 intValue];

But for some reason bookval_开发者_开发问答int_curr seems to be returning nil. Am I doing something wrong ?


Check the types of str1, str2 and bookval_int_curr:

NSString *str1 = @"52";
NSString *str2 = @"50";

int bookval_int_curr = [str1 intValue] - [str2 intValue];

And check, that str1 and str2 is not equal nil.


I Assume that str1 and str2 are strings. Then if they doesn’t begin with a valid decimal text representation of a number, NSString would return 0. 0 - 0 = 0. If you are trying to assign 0 to the object, then it's address would be nil.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜