0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows PowerShell で Unicode(UTF-16LE) から UTF-8(BOM無し) に変換

Posted at

Windows PowerShell の文字コードの互換性がつらい

$File = get-item "sample.txt"
$OutFile = "{0}\{1}.UTF8{2}" -f $File.Directory, $File.BaseName, $File.Extension

# 入力ファイルのエンコーディング
# Windows では UTF-16LE のことを Unicode と呼ぶ
$Encoding = [System.Text.Encoding]::Unicode
$content = [System.IO.File]::ReadAllText($File.FullName, $Encoding)

# 出力ファイルは暗黙的に UTF-8(BOM無し) で作成される
[System.IO.File]::WriteAllText($OutFile, $content)

Windows Terminal のコンソールが UTF-8 だったり、再現できなくてすごくつらい。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?