Concatenate
edwgeo
Posts: 8
I need conacatenate two varaibles for example:
a=5
b=0
c=a + b // resul=50
what is the function for to realize this operation.
I do not want that the result is c=5
a=5
b=0
c=a + b // resul=50
what is the function for to realize this operation.
I do not want that the result is c=5
0
Comments
c = (a*10) + b
Another way would be to convert to a Char and back to an integer...
yuri my Dutch friend, your statement is a real head scratcher. It’s kind of like telling someone that is traveling north and wants to head west that the best way is to take 3 right turns instead of 1 left. It’s certainly one way to do it and it’s good to know for future reference but I don’t see how you can go wrong with c = (a*10) + b. Math is your friend.
…tfel egats gnitixE
Edit: Exited wrong direction
Too funny! Good point though Joe!
I think Yuri is referring to the possibility that a is not always going to be the tens digit. If for some reason a=11 and b=13, the best way (in my mind) to end up with 1113 is to do the ATOI("ITOA(a),ITOA(b)") method. You could use math and conditional statements to determine how many digits are in b and then multiply a accordingly, but the conversion method is shorter.
If a is ALWAYS a single digit 10s place, and b is ALWAYS a single digit 1s place, then I would agree that the best method is the arithmetic method.
Jeff
Actually it doesn’t matter how many digits a is.
If a=12345 and b=9 then c=(12345*10)+9=123459 and the math works.
But, and that’s a big butt, if b > 9 then yes indeed I’m entirely wrong (damn you Jeff and yuri! ) and I didn’t think it all the way through.
Can somebody please get me a towel so I can wipe the egg off me face? Screw the math.
Backpedaling stage right…
hahahaha
i think the trouble started with me not formatting my sentence correctly
i've learned from my own faults that creating something that works for one cause can create errors when using it for another... always create something that works whichever way you go (norht, east, south, west )
I'd rather take 3 right and get to my location, than taking one left and fall into the ocean (or something, that's some Japanese stuff there! )