Powershell不断转换为ASCII [英] Powershell keeps converting to ascii

查看:242
本文介绍了Powershell不断转换为ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遵循了指南:使用Windows PowerShell在Microsoft Word文档中查找并替换一个单词

I've followed the guide here: Use Windows PowerShell to Look for and Replace a Word in a Microsoft Word Document

我的问题是,如果我将UTF8字符串放入搜索文件中,则会在进入单词应用程序之前将其转换为ASCII.

My problem is that if I put a UTF8 string into the search filed it gets converted to ASCII before going into the word application.

如果您只是复制并粘贴他的代码,然后将查找文本更改为日语,例如karerシウム

If you simply copy and paste his code and change the find text to something like Japanese: カルシウム

它将投入工作并搜索ascii等效项:ã,«ƒ«ã,·ã‚¦ãƒ

It will go into work and search for the ascii equivalent: カルシウム

我已经尝试过所有关于将输入和输出设置为UTF8的建议,但是似乎没有任何效果.我什至无法使Powershell控制台实际显示日语字符,我所得到的只是盒子.我认为这可能与以下事实有关:我只有3种字体,也许它们中的任何一种都不能在控制台中显示日文字符...但是我对此并不在意,我希望能够发送使用UTF8中的日语字符进行查找和替换.

I have tried every suggestion about setting input and output to UTF8 that I can find but nothing seems to be working. I can't even get the powershell console to actually display Japanese characters, all I get are boxes. I think that might have something to do with the fact that I only have 3 fonts and perhaps none of them can display the Japanese characters in the console...but I don't care about that, I want to be able to send the Japanese characters in UTF8 for the find and replace.

有帮助吗?

推荐答案

对于那些不断将输出编码转换为ASCII或Unicode的人

For people who keep getting output encoding to ASCII or Unicode all the time, you can set output encoding to whatever encoding you want from Microsoft blog $OutputEncoding

  1. PS C:\> $OutputEncoding//告诉您所使用的默认编码
  2. PS C:\> $OutputEncoding = [Console]::OutputEncoding//更改为控制台,也可以对其进行设置
  3. $OutputEncoding = New-Object -typename System.Text.UTF8Encoding//任何您想看的日语
  4. PS C:\> $OutputEncoding//验证 编码
  1. PS C:\> $OutputEncoding //tells you what default encoding you have
  2. PS C:\> $OutputEncoding = [Console]::OutputEncoding //change to the console or you can set it
  3. $OutputEncoding = New-Object -typename System.Text.UTF8Encoding //whatever you want, look up japanese
  4. PS C:\> $OutputEncoding // verify the encoding

这篇关于Powershell不断转换为ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆