Autohotkey:如何将撇号 (") 添加到字符串
Autohotkey: How to add apostrophe (") to string
我有一个自动热键脚本:
IfInString, pp_text, %A_Space%
{
pp_text := %pp_text%
}
所以如果 %pp_text% 包含 space 我想在开头和结尾添加 "
示例:
pp_text = 你好世界
然后应该成为
pp_text = "Hello World"
我该怎么做
您 escape a quote by by putting another quote next to it and you concatenate 使用连接运算符 .
,但实际上您也可以在 99% 的情况下省略运算符。
脚本中需要修复的其他问题:
摆脱那个超级弃用的遗留命令并使用 InStr()
代替。
当您在表达式中时,只需键入变量名称即可引用变量。您使用的双 %
是引用变量的传统方式。
所以它在旧命令中是正确的,但在现代 :=
赋值中不正确。
您也可以省略单行 if 语句中的括号。但这当然只是个人喜好。
完整脚本:
If (InStr(pp_text, A_Space))
pp_text := """" pp_text """"
四个引号,因为最外面的两个引号指定我们正在输入一个字符串。
Variable names in an expression are not enclosed in percent signs.
Consequently, literal strings must be enclosed in double quotes to
distinguish them from variables.
To include an actual quote-character
inside a literal string, specify two consecutive quotes as shown twice
in this example: "She said, ""An apple a day.""".
pp_text := "Hello World"
If InStr(pp_text, " ")
pp_text := """Hello World"""
MsgBox % pp_text
编辑:
如用户 0x464e 所解释的那样,要在输出表达式中使用变量的名称(而不是其文字文本),您需要四个引号。
pp_text := "Hello World"
If InStr(pp_text, " ")
pp_text := """" pp_text """"
MsgBox % pp_text
我有一个自动热键脚本:
IfInString, pp_text, %A_Space%
{
pp_text := %pp_text%
}
所以如果 %pp_text% 包含 space 我想在开头和结尾添加 "
示例: pp_text = 你好世界 然后应该成为 pp_text = "Hello World"
我该怎么做
您 escape a quote by by putting another quote next to it and you concatenate 使用连接运算符 .
,但实际上您也可以在 99% 的情况下省略运算符。
脚本中需要修复的其他问题:
摆脱那个超级弃用的遗留命令并使用 InStr()
代替。
当您在表达式中时,只需键入变量名称即可引用变量。您使用的双 %
是引用变量的传统方式。
所以它在旧命令中是正确的,但在现代 :=
赋值中不正确。
您也可以省略单行 if 语句中的括号。但这当然只是个人喜好。
完整脚本:
If (InStr(pp_text, A_Space))
pp_text := """" pp_text """"
四个引号,因为最外面的两个引号指定我们正在输入一个字符串。
Variable names in an expression are not enclosed in percent signs.
Consequently, literal strings must be enclosed in double quotes to distinguish them from variables.
To include an actual quote-character inside a literal string, specify two consecutive quotes as shown twice in this example: "She said, ""An apple a day.""".
pp_text := "Hello World"
If InStr(pp_text, " ")
pp_text := """Hello World"""
MsgBox % pp_text
编辑:
如用户 0x464e 所解释的那样,要在输出表达式中使用变量的名称(而不是其文字文本),您需要四个引号。
pp_text := "Hello World"
If InStr(pp_text, " ")
pp_text := """" pp_text """"
MsgBox % pp_text