在 Autohotkey 中格式化列表框的输出?
In Autohotkey Format the output of a ListBox?
在 Autohotkey 中,我有以下代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
send, % MyListBox
return
输出是,例如:
Strawberries|Beans|Turnips
但我希望它是:
Strawberries, Beans, Turnips,
我应该如何进行?
提前致谢
听起来像是 RegEx 的工作。
使用 RegExReplace() with the MyListBox variable as the haystack and "\|" as the needle. See this interactive 解释这个特定的 RegEx 指针。
将字符串的替换版本保存在名为 NewStr
的变量中,我们得到了这行代码:
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
当前代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
MsgBox % NewStr
send, % NewStr
return
不过,这个版本没有添加尾随“,”。为了添加它,我们只需将一个“,”附加到我们刚刚使用 NewStr.=", "
创建的 NewStr 变量
最终代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
NewStr.=", "
MsgBox % NewStr
send, % NewStr
return
在 Autohotkey 中,我有以下代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
send, % MyListBox
return
输出是,例如:
Strawberries|Beans|Turnips
但我希望它是:
Strawberries, Beans, Turnips,
我应该如何进行?
提前致谢
听起来像是 RegEx 的工作。
使用 RegExReplace() with the MyListBox variable as the haystack and "\|" as the needle. See this interactive 解释这个特定的 RegEx 指针。
将字符串的替换版本保存在名为 NewStr
的变量中,我们得到了这行代码:
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
当前代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
MsgBox % NewStr
send, % NewStr
return
不过,这个版本没有添加尾随“,”。为了添加它,我们只需将一个“,”附加到我们刚刚使用 NewStr.=", "
最终代码:
^r::
Gui, Add, ListBox, Multi vMyListBox r10, Strawberries|Pears|Oranges|`r|Beans|Peas|Tomatoes|Turnips|
Gui, Add, Button, Default, OK
Gui, Show
return
ButtonOK:
Gui, Submit
MsgBox % MyListBox
NewStr := RegExReplace(MyListBox, "\|" , Replacement := ", ")
NewStr.=", "
MsgBox % NewStr
send, % NewStr
return