Monday, April 6, 2020

PowerhShell: Escape Sequences (NewLine, Tab, BackSpace, etc)

The ultimately goal in this series of blog posts is to demonstrate PowerhSell being used with Selenium to automate Chrome. When automating a browser, invoking an Enter key is handy. This posts discusses PowerShell escape sequenecde which includes `n which is the escape sequence for the Enter key.  The character before the n key in the previous sentence is the back quote. The back quote character (`) shares the same key as the tilde on standard English keyboards. The back quote character is called by many names such as acute, backtick, left quote, or a open quote, and or backquote. In PowerShell the back quote is used to indicate an escape sequence in a string.

In a previous post (PowerShell: Comparing Version Numbers) the following code snippet was show which shows a back quote being used to esape the $ so that the variable is not injected into the double quoted string (`$versionCurrent and `$versionPrevious contain the escaped $ character):
    Write-Host
        "Correct: `$versionCurrent ($versionCurrent) -gt" +
        "`$versionPrevious ($versionPrevious)"


As was discussed above, the `n escape sequence corresponds to the Enter key. The following escape sequences are defined in my Microsoft's PowerShell documentation, About Special Characters:


The `t escape sequence is useufl in creating tab-seperated-value files (TSV's). The rest of the escape sequences have their uses but for our taget purpose is to automate Chrome using PowerShell and Selenium, they might not serve much of a use in that endeavor.



No comments :

Post a Comment