How to add apostrophe (") to string?

前端 未结 3 787
终归单人心
终归单人心 2021-01-23 14:19

I have this AutoIt script:

ControlFocus(\"Open\", \"\", \"Edit1\")
Sleep(500)
ControlSetText(\"Open\", \"\", \"Edit1\", $CmdLine[1])
Sleep(500)
ControlClick(\"Op         


        
3条回答
  •  遇见更好的自我
    2021-01-23 14:45

    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 …

    1. Double double-quote

      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.".

    2. Single quote

      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.'.

    3. ASCII code

      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.

提交回复
热议问题