This works:
Code: Select all
"_Initialize"
perm $Hide;
$Hide = _Menu B
"Menu A" msg a
"$Hide" msg b
"Menu C" msg cCode: Select all
"_Initialize"
perm $Hide;
$Hide = _Menu B
"Menu A" msg a
"$Hide|<xyicons>\USB.ico" msg b
"Menu C" msg cCode: Select all
"_Initialize"
perm $Hide;
$Hide = _Menu B
"Menu A" msg a
"$Hide" msg b
"Menu C" msg cCode: Select all
"_Initialize"
perm $Hide;
$Hide = _Menu B
"Menu A" msg a
"$Hide|<xyicons>\USB.ico" msg b
"Menu C" msg cDon,admin wrote:Confirmed and fixed.
Code: Select all
$Hide = '_Menu B'Code: Select all
perm $Hide = "_Menu B";Code: Select all
$a = 'A string.';
msg '$a = "' . $a . '"';Code: Select all
$a = 'A string.';
msg "a = '$a'";Code: Select all
$a = 'A string.';
msg "a = ""$a""";And it is nothing exotic. Many wel-known languages, e.g. PHP, work exactly the same.Using Quotes in Scripting
It's strongly recommended that you (double- or single-) quote your strings! While the script engine is currently still permissive with unquoted strings (msg Hi! works) this might not be so in the future, so you better do msg "Hi!" right away!
(1) Everything is either in double-quotes, or in single-quotes, or outside of any quotes.
(2) To have double-quotes inside double-quotes they must be doubled.
(3) To have single-quotes inside single-quotes they must be doubled.
(4) Variables are resolved in double-quotes and outside of any quotes, but not in single-quotes.
What if the string contains a double quote literal?binocular222 wrote:Double quote for string
I'm sorry but I have to rain on this parade.. just like XY, AHK CAN be that "simple", but it does not HAVE to be.binocular222 wrote:This makes me love AHK more. I've never made wrong quoting in AHK.
Double quote for string; no quote for the rest. No double-triple quotes, no single quote, no single-doble quote. Quite simple.
Variables are sometimes enclosed in percents and sometimes not.Retrieving the contents of variables: Like the two methods of storing values, there are also two methods for retrieving them: traditional and expression. The traditional method requires that each variable name be enclosed in percent signs to retrieve its contents. For example:
MsgBox The value in the variable named Var is %Var%.
CopyOfVar = %Var%
By contrast, the expression method omits the percent signs around variable names, but encloses literal strings in quotes. Thus, the following are the expression equivalents of the previous examples:
MsgBox % "The value in the variable named Var is " . Var . "." ; A period is used to concatenate (join) two strings.
CopyOfVar := Var
Oh there's double-quotes too!if (CurrentSetting > 100 or FoundColor <> "Blue")
MsgBox The setting is too high or the wrong color is present.
In the example above, "Blue" appears in quotes because it is a literal string. 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."""
Ooff! I love AHK as well, though I'm not using it as much these days, but I'm not so sure it's a better example of handling these intricacies.When running a program via Comspec (cmd.exe) -- perhaps because you need to redirect the program's input or output -- if the path or name of the executable contains spaces, the entire string should be enclosed in an outer pair of quotes. In the following example, the outer quotes are shown in red and all the inner quotes are shown in black:
Run %comspec% /c ""C:\My Utility.exe" "param 1" "second param" >"C:\My File.txt""
Code: Select all
Test := "double quote "" is escaped by prefixing double quote"
msgbox %Test%Thanks.binocular222 wrote:Literal " is escaped by prefixing " instead of apostrophe:Result:Code: Select all
Test := "double quote "" is escaped by prefixing double quote" msgbox %Test%
double quote " is escaped by prefixing double quote