【发布时间】:2015-06-07 03:10:48
【问题描述】:
我知道之前有人问过一个类似的问题:
How to concatenate a number and a string in auto hotkey
但这个问题只考虑数字。我的问题有点不同。例如:
myStr = A literal string
myInt = 5
现在我希望将两者连接成一个新字符串:5A literal string
这是我迄今为止尝试过的:
newStr = %myInt%%myStr% ;Result: Error illegal character found
newStr = % myInt myStr ;Result: Some number
convertString = (%myInt% . String)
newStr = %convertString%%myStr% ;Result: Error illegal character found
似乎无论我尝试什么,AHK 都无法处理将整数与文本字符串连接起来。有没有人有这方面的经验并知道如何让它发挥作用?
编辑
我应该补充一点,我无法通过执行myInt = "5" 来解决问题,因为我需要使用myInt++ 在循环中对整数进行操作。我还没有想出的第二个问题是:如何将 unicode 添加到字符串中?我以为是U+0003,但这似乎不起作用。
编辑 2
似乎其他人没有得到相同的结果。我已经更新了 AHK,但问题仍然存在。所以我会在这里包含我的确切代码,也许我做错了什么?
global OriText ;Contains textstring
global NewText ;Empty
global ColorNumber
ColorNumber = 2
convert_text(){
StringSplit, char_array, OriText
Loop, %char_array0%
{
thisChar := char_array%a_index%
NewText += % ColorNumber thisChar
MsgBox, %NewText%
ColorNumber++
if (ColorNumber = 13){
ColorNumber = 2
}
}
GuiControl,, NewText, %NewText%
ColorNumber = 2
}
简短的解释:我正在构建一个小工具,它会自动为 irc 中的文本着色,为每个字符添加不同的颜色。因此将字符串拆分为一个数组并尝试添加:
U:0003ColorNumberCharacter
其中 U:0003 应该是 mIRC 中使用 (Ctrl+K) 的字符的 unicode。
【问题讨论】:
-
如果在 double% 之间添加一些东西会发生什么?例如,newStr = %myInt%X%myStr%
-
@donjuedo 也试过了。结果相同。非法字符或字符串都被转换为某个数字并添加到其中。
-
我没有看到相同的结果?事实上,它完全按照它应该的方式工作。我想您可能需要重新安装或更新到最新版本的 AutoHotkey?在 ahkscript.org 下载。
-
没关系,明白了。将测试
-
@ahkcoder 还是同样的问题。我已经用我的确切代码更新了我的问题。也许我在那里做错了什么?
标签: autohotkey