Skip to content

Instantly share code, notes, and snippets.

@stknohg
Last active February 3, 2023 02:05
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stknohg/c84b2a8b6aa02b25a327c1420b0a1695 to your computer and use it in GitHub Desktop.
Save stknohg/c84b2a8b6aa02b25a327c1420b0a1695 to your computer and use it in GitHub Desktop.
PowerShellでBOM無しUTF8を書くサンプル
# 例1
"書き込み内容" `
| % { [Text.Encoding]::UTF8.GetBytes($_) } `
| Set-Content -Path ".\BOMlessUTF8.txt" -Encoding Byte
# 例2
Get-Content -Path ".\Source.txt" -Raw -Encoding Default `
| % { [Text.Encoding]::UTF8.GetBytes($_) } `
| Set-Content -Path ".\BOMlessUTF8.txt" -Encoding Byte
# 例3
# Out-Stringを使って明示的に改行込みの文字列にする
# 例2と異なり -Raw オプションが付いていないのに注意
Get-Content -Path ".\Source.txt" -Encoding Default `
| Out-String `
| % { [Text.Encoding]::UTF8.GetBytes($_) } `
| Set-Content -Path ".\BOMlessUTF8.txt" -Encoding Byte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment