Home AMX User Forum NetLinx Studio
Options

Concatenate

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

Comments

  • Options
    Joe HebertJoe Hebert Posts: 2,159
    If a always represents the 10 position and b always represents the 1 position then you can just do the math:

    c = (a*10) + b
    edwgeo wrote:
    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
  • Options
    dchristodchristo Posts: 177
    edwgeo wrote:
    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

    Another way would be to convert to a Char and back to an integer...
    a = 5
    b = 0
    c = Atoi("Itoa(a), Itoa(b)")   // c = 50
    
  • Options
    yuriyuri Posts: 861
    concatenate to a char and then ATOI() back like dchristo says works best, can't go wrong :)
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Two Wrongs Don't Make a Right but Three Rights Do Make a Left

    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
    yuri wrote:
    concatenate to a char and then ATOI() back like dchristo says works best, can't go wrong :)

    Edit: Exited wrong direction
  • Options
    jjamesjjames Posts: 2,908
    Joe Hebert wrote:
    ?tfel egats gnitixE

    Edit: Exited wrong direction

    Too funny! Good point though Joe!
  • Options
    Spire_JeffSpire_Jeff Posts: 1,917
    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
  • Options
    Joe HebertJoe Hebert Posts: 2,159
    Excellent Point, Jeff!
    Spire_Jeff wrote:
    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.
    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? :D Screw the math.

    Backpedaling stage right…
  • Options
    yuriyuri Posts: 861
    Joe Hebert wrote:
    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? :D Screw the math.

    Backpedaling stage right?

    hahahaha :D
    i think the trouble started with me not formatting my sentence correctly :p

    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 :p )

    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! :D )
Sign In or Register to comment.