简体   繁体   English

在批处理或VBS脚本中将宽字符转换为多字节?

[英]Convert wide character to multibyte in a batch or VBS script?

Can anyone think of a way to convert a wide character file to a multibyte file in a batch or VBS script? 谁能想到一种将批处理或VBS脚本中的宽字符文件转换为多字节文件的方法吗?

Let's say I have a file hello.txt that contains this text in wide character: "HELLO WORLD\\r\\n". 假设我有一个文件hello.txt,其中包含以下宽字符文本:“ HELLO WORLD \\ r \\ n”。 In hex format that would be: 十六进制格式为:

48 00 45 00 4C 00 4C 00 4F 00 20 00 57 00 4F 00 52 00 4C 00 44 00 0D 00 0A 00

I would like to convert it to a multi-byte file, ie, to contain this: 我想将其转换为多字节文件,即包含以下内容:

48 45 4C 4C 4F 20 57 4F 52 4C 44 0D 0A

However, I need to do it either in a CMD file or a VBS script. 但是,我需要在CMD文件或VBS脚本中执行此操作。 Is this possible? 这可能吗?

Thanks. 谢谢。

In PowerShell 在PowerShell中

PowerShell "Get-Content -Encoding Unicode hello.txt | Out-File -Encoding ASCII out.txt"

CharSets 字符集下

  • Unicode = UCS-2 LE Unicode = UCS-2 LE
  • BigEndianUnicode = UCS-2 BE BigEndianUnicode = UCS-2 BE
  • UTF8 = UTF-8 with BOM UTF8 =具有BOM的UTF-8
  • UTF7 = UTF-7 UTF7 = UTF-7
  • ASCII = ASCII ASCII = ASCII

Get-Content 获取内容

Out-File 出文件

first: 第一:

<"UNICODE.TXT">"ASCII.TXT" FIND /V ""

second: 第二:

type "UNICODE.TXT">"ASCII.TXT"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM