I have this AutoIt script:
ControlFocus(\"Open\", \"\", \"Edit1\")
Sleep(500)
ControlSetText(\"Open\", \"\", \"Edit1\", $CmdLine[1])
Sleep(500)
ControlClick(\"Op
I tried
ControlSetText("Open", "", "Edit1", $CmdLine[1] & """)
but this results into error:Unterminated string.
.
No attempt to add double quote before $CmdLine[1]
was made (only after).
I want to add
"
before and after my string …
As per Documentation - Intro - Datatypes - Strings:
If you want a string to actually contain a double-quote use it twice …
You can also use single-quotes …
As per Documentation - FAQ - 3. Why do I get errors when I try and use double quotes (") ?:
If you want to use double-quotes inside a string then you must "double them up". So for every one quote you want you should use two. …
"
becomes:
$sString = """"
This is a "quoted" string.
becomes:
$sString = "This is a ""quoted"" string."
.
As per Documentation - FAQ - 3. Why do I get errors when I try and use double quotes (") ?:
… or use single quotes instead: …
"
becomes:
$sString = '"'
This is a "quoted" string.
becomes:
$sString = 'This is a "quoted" string.'
.
As per Documentation - Function Reference - Chr() :
Returns a character corresponding to an ASCII code.
"
becomes:
$sString = Chr(34)
34 is the " -sign's ASCII code, so This is a "quoted" string.
becomes:
$sString = "This is a " & Chr(34) & "quoted" & Chr(34) & " string."
Or per StringFormat() :
$sString = StringFormat("This is a %squoted%s string.", Chr(34), Chr(34))
Related.
AutoIt supports two types of quoting, which are interchangeable:
MsgBox(0, "single-double", 'hello " world') ; hello " world
MsgBox(0, "double-single", "hello ' world") ; hello ' world
MsgBox(0, "double-double", "hello "" world") ; hello " world
MsgBox(0, "single-single", 'hello '' world') ; hello ' world
I personally prefer the first two (depending on how my string looks like).
So one of those should do:
ControlSetText("Open", "", "Edit1", $CmdLine[1] & '"') ; Changing quoting where needed
ControlSetText('Open', '', 'Edit1', $CmdLine[1] & '"') ; Changing quoting consistent
Autoit uses pairs quotes to indicate a single instance within a string.
E.g., """"
(notice, there are 4 double quotation marks) acts as a single double-quote within the string.
So $CmdLine[1] & """"
should add a single double-quote.
See AutoIt's documentation. https://www.autoitscript.com/autoit3/docs/intro/lang_datatypes.htm has a section on strings.