Skip to content

Commit df461d8

Browse files
authored
Move encoding script to gist
1 parent 5c4dbec commit df461d8

File tree

1 file changed

+1
-35
lines changed

1 file changed

+1
-35
lines changed

reference/docs-conceptual/components/vscode/vscode-encoding-configuration.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -243,41 +243,7 @@ In PowerShell 5+ you can find your default encoding with this:
243243
[psobject].Assembly.GetTypes() | ? { $_.Name -eq 'ClrFacade'} | % { $_.GetMethod('GetDefaultEncoding', [System.Reflection.BindingFlags]'nonpublic,static').Invoke($null, @()) }
244244
```
245245

246-
To find out what your PowerShell session will infer a script without a BOM to be encoded in, run:
247-
248-
```powershell
249-
$badBytes = [byte[]]@(0xC3, 0x80)
250-
251-
$utf8Str = [System.Text.Encoding]::UTF8.GetString($badBytes)
252-
253-
$bytes = [System.Text.Encoding]::ASCII.GetBytes('Write-Output "') + $badBytes + [byte[]]@(0x22)
254-
255-
$path = Join-Path ([System.IO.Path]::GetTempPath()) 'encodingtest.ps1'
256-
257-
try
258-
{
259-
[System.IO.File]::WriteAllBytes($path, $bytes)
260-
261-
switch (& $path)
262-
{
263-
$utf8Str
264-
{
265-
return 'UTF-8'
266-
break
267-
}
268-
269-
default
270-
{
271-
return 'Windows-1252'
272-
break
273-
}
274-
}
275-
}
276-
finally
277-
{
278-
Remove-Item $path
279-
}
280-
```
246+
To find out what your PowerShell session will infer a script without a BOM to be encoded in, run [this script](https://gist.github.com/rjmholt/3d8dd4849f718c914132ce3c5b278e0e).
281247

282248
It's not strictly possible to force PowerShell to use an input encoding,
283249
and PowerShell 5.1 and below default to [Windows-1252] when there is no BOM.

0 commit comments

Comments
 (0)