PowerShellでBOM無しUTF8を書くサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 例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