$path = "s:\Source\Gloria\Unimarc\unimarc\unimarc\Helper_LibraryDelaySettings.cs" $utf8 = [System.Text.Encoding]::GetEncoding(65001) $cp949 = [System.Text.Encoding]::GetEncoding(949) # Read the CURRENT mangled file as UTF-8 $mangledString = [System.IO.File]::ReadAllText($path, $utf8) # Convert each character to its CP949 bytes # Note: This is tricky because some "characters" might be multiple bytes in CP949 # but here each character in the string represents what CP949 read from the original UTF-8 bytes. $byteList = New-Object System.Collections.Generic.List[byte] foreach ($char in $mangledString.ToCharArray()) { $cBytes = $cp949.GetBytes($char) foreach ($b in $cBytes) { $byteList.Add($b) } } # Now interpret these bytes as UTF-8 (the original encoding) $restored = $utf8.GetString($byteList.ToArray()) Write-Host "--- Attempted Restoration ---" Write-Host ($restored -split "`r`n" | select -First 10)