How to concatenate a number and a string in an automatic hotkey

I have the following script hotkey:

A:= 5 B := "7" C := AB MsgBox %C% 

The third line does not work.

I expect the output to be "57"

I tried the following:

 C := %A%.%B% C := (A).(B) C := (AB) C := (%A%.%B%) C := (%A%).(%B%) 

None of them work

Can someone tell me how to do this?

I am using version 1.1.09.04

Just upgraded to the latest version 1.1.14.01 and it's still the same

+8
autohotkey
source share
1 answer

You can distinguish between expressions ( := ) and "normal" values ​​( = ). Your goal can be satisfied with several approaches, as shown in the following examples:

 a := 5 b := 7 x := 6789 ; String concatenation str1 = %a%%b% ; or as an expression str2 := ab ; or with explicit concatenation operators str3 := a . b ; Mathematical "concatenation" ; if b has exactly one digit val1 := a*10 + b ; for any integer val2 := a * (10**StrLen(x)) + x ; ** is the "power" operator msgbox, str1 = %str1%`nstr2 = %str2%`nstr3 = %str3%`nval1 = %val1%`nval2 = %val2% 

This code will print:

 str1 = 57 str2 = 57 str3 = 57 val1 = 57 val2 = 56789 

In AHK, all of these methods must be quasi-equivalent: they produce the same output. The mathematical approach marks variables as numbers, leading to possible trailing zeros that you might want Round() before displaying. The result of our string concatenation can also be used as a number, since AHK automatically blocks them if necessary. For example, you can calculate z := str1 - 1
and he will rate to 56 .
I personally prefer the mathematical approach, as this will result in the actual number rather than the string, which seems logical.

+18
source share

All Articles