如何在自动热键中连接数字和字符串 [英] How to concatenate a number and a string in auto hotkey

查看:167
本文介绍了如何在自动热键中连接数字和字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下自动热键脚本:

I have the following auto hotkey script:

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

第三行不起作用.

我期望输出为"57"

I'm expecting output of "57"

我尝试了以下操作:

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

没有一项工作

有人可以告诉我该怎么做吗?

Can anyone tell me how to do it?

我正在使用1.1.09.04版

I'm using version 1.1.09.04

仅更新至最新版本1.1.14.01,并且仍保持不变

Just updated to latest version 1.1.14.01 and its still the same

推荐答案

您可以区分表达式(:=)和常规"值分配(=).您的目标可以通过以下几种方法来实现,如以下示例所示:

You have distinguish between expressions (:=) and "normal" value assigments (=). Your goal can be met 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 := a b
; 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%

此代码将打印:

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

在AHK中,所有这些方法都应该是准等效的:它们产生相同类型的输出.数学方法将变量标记为数字,导致可能的尾随零,您可能需要在显示前将其Round().字符串连接的输出也可以用作数字,因为AHK会在必要时自动将它们装箱.例如,您可以计算
z := str1 - 1
它将评估为56.
我个人更喜欢数学方法,因为它会导致产生一个实际的数字而不是一个字符串,这似乎是合乎逻辑的.

In AHK, all of these methods should be quasi-equivalent: They produce the same kind of output. The mathematical approach marks the variables as numbers, leading to possible trailing zeros, which you may want to Round() before displaying. The output of our string concatenation can be used as a number as well, since AHK auto-boxes them if neccessary. For example, you could calculate
z := str1 - 1
and it would evaluate to 56.
I personally prefer the mathematical approach, since it will result result in an actual number and not a string, which seems only logical.

这篇关于如何在自动热键中连接数字和字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆