从文件中检索日语或本地化字符串

时间:2012-01-27 01:22:02

标签: powershell

我有以下代码从mht文件中检索日语或本地化字符串。我已经使用了这里列出的几乎所有编码参数(未知,字符串,unicode,bigendianunicode,utf8,utf7,utf32,ascii,默认,oem)并进行了验证。它总是打印垃圾字符而不是原始的中文或日文名称

$log = "c:\scripts\meta.mht"
$patt = 'title'
$indx = Select-String $patt $log | ForEach-Object {$_.LineNumber}
write-host (Get-Content $log)[$indx] | out-file -encoding string c:\scripts\temp1.xml

有人可以帮我打印本地化的字符串吗?我应该使用哪种编码参数? 我试过所有列出的参数但没有运气(未知,字符串,unicode,bigendianunicode,utf8,utf7,utf32,ascii,默认,oem)

提前感谢。

1 个答案:

答案 0 :(得分:4)

尝试更改Get-Content的编码,如下所示:

write-host (Get-Content -Path $log -Encoding UTF8)[$indx] | out-file -encoding UTF8 c:\scripts\temp1.xml

我不确定您是否需要UTF8或UNICODE,请同时使用Get-ContentOut-File