Author : MD TAREQ HASSAN | Updated : 2023/03/17

Characters in PowerShell

Character type variable

[char] $ch = "`0" # null character
Write-Host $ch

$jChar = 'j'
Write-Host $jChar

[char] $jCharFromInt =  [char] 106
Write-Host $jCharFromInt

Escape character

In PowerShell, backtick (or grave acent) “`” is used as escape character

$x = 15
Write-Host "Value of `$x variable is $x" # Value of $x variable is 15

Special character

# `n: New line
# `r: carriage return

Write-Host "Hey!`n`rhow are you?"

Read-Host "Enter your name"
Read-Host "Enter your name`n"
Read-Host "Enter your name`n`r"

More about: Special Characters

Character code escape sequence

# only unicode ("`u{hex}"), unlike C# no hex ("`x{hex}")

$jCharFromUnicode = "`u{006A}";
Write-Host $jCharFromUnicode # "j"

$thumbsUp = "`u{1F44D}"
Write-Host $thumbsUp # "👍"