PowerShell: Byte to String

Create some string from byte array and print it as ASCII string

#'a' is 0x61, 'b' is 0x62, 'c' is 0x63, 'd' is 0x64

PS C:\> $str1 = [byte[]] (0x61, 0x62, 0x63, 0x64)
PS C:\> [System.Text.Encoding]::ASCII.GetString($str1)
abcd

Create some string from byte array and print it as UTF8 string

PS C:\> $str2= [byte[]] (0xF0, 0x9F, 0x92, 0xBF)
PS C:\> [System.Text.Encoding]::UTF8.GetString($str1)
💿


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *