Hello, sorry for my bad title (and noob question), but how can I add two numbers like 7 and 6 and the result should be 76. Is there a operation symbol in objective-c?
Thanks and sorry for my bad English.
Hello, sorry for my bad title (and noob question), but how can I add two numbers like 7 and 6 and the result should be 76. Is there a operation symbol in objective-c?
Thanks and sorry for my bad English.
That's not a numeric operation, it's string concatenation.
http://stackoverflow.com/questions/510269/how-do-i-concatenate-strings-in-objective-c
There is no built in symbol to concatenate numbers. However, you can accomplish this by doing:
int first; /* Assuming this is initialized to the first number */
int second; /* Assuming this is initalized to the second number */
int myVal = [[NSString stringWithFormat:@"%d%d",first, second] intValue];
If you want two numbers x and y to add to xy, you can do
10*x + y.
For 7 and 6
7*10 + 6 = 76
Hi, I don't know much about objective-c but I would say:
If you get the numbers from an array, like nums= array(7,6), initialize result= 0 and then do a foreach on them. For each value you find, do : res= res*10 + value. At the end, even if you got 7 numbers to concatenate you'll get the result right. ie:
Array nums= Array(7,6,8,9); int res= 0; int value; foreach (value in nums) res= res*10 + value;
If you can use strings, just concatenate them like suggested above. there is probably a function to concatenate all values from an array as well to make it flexible.
Hope it helps
C^