- 1 year ago
Show hex values of Powershell output of GetInvalidFileNameChars()
To display the hexadecimal values of the output from GetInvalidFileNameChars()
in PowerShell, you can use a loop to iterate over each character in the returned array and convert it to its hexadecimal representation. Here's an example:
powershell$invalidChars = [System.IO.Path]::GetInvalidFileNameChars()
foreach ($char in $invalidChars) {
$hexValue = '0x{0:X2}' -f [int]$char
Write-Host $hexValue
}
In this code, $invalidChars
holds the array of invalid characters returned by GetInvalidFileNameChars()
. The loop iterates over each character in the array, and [int]$char
converts each character to its corresponding ASCII value. The '{0:X2}' -f [int]$char
format string is used to format the ASCII value as a two-digit hexadecimal number, prefixed with "0x". Finally, Write-Host
is used to display the hexadecimal value.
When you run this code, it will print the hexadecimal values of the invalid characters in the console output. For example:
python0x00
0x01
0x02
...
Note that GetInvalidFileNameChars()
returns an array of characters that are invalid in file names across different platforms, so the hexadecimal values represent the ASCII values of those characters.