在字符集之间转换文本文件的最快、最简单的工具或方法是什么?

具体来说,我需要从UTF-8转换为ISO-8859-15,反之亦然。

一切都可以:你最喜欢的脚本语言的一行程序,命令行工具或其他用于操作系统的实用程序,网站等等。

目前为止的最佳解决方案:

在 Linux/UNIX/OS X/cygwin 上:

Gnu iconv suggested by Troels Arvin is best used as a filter. It seems to be universally available. Example: $ iconv -f UTF-8 -t ISO-8859-15 in.txt > out.txt As pointed out by Ben, there is an online converter using iconv. recode (manual) suggested by Cheekysoft will convert one or several files in-place. Example: $ recode UTF8..ISO-8859-15 in.txt This one uses shorter aliases: $ recode utf8..l9 in.txt Recode also supports surfaces which can be used to convert between different line ending types and encodings: Convert newlines from LF (Unix) to CR-LF (DOS): $ recode ../CR-LF in.txt Base64 encode file: $ recode ../Base64 in.txt You can also combine them. Convert a Base64 encoded UTF8 file with Unix line endings to Base64 encoded Latin 1 file with Dos line endings: $ recode utf8/Base64..l1/CR-LF/Base64 file.txt

在Windows Powershell (Jay Bazuzi)上:

PS C:\> gc - zh utf8 in.txt | out - zh ascii out.txt

(但是没有ISO-8859-15支持;它说支持的字符集是unicode, utf7, utf8, utf32, ascii, bigendianunicode, default和oem。)

Edit

你是指iso-8859-1支持吗?使用"String"可以做到这一点,反之亦然

gc -en string in.txt | Out-File -en utf8 out.txt

注意:可能的枚举值是“Unknown, String, Unicode, Byte, BigEndianUnicode, UTF8, UTF7, Ascii”。

CsCvt - Kalytta的字符集转换器是另一个伟大的基于命令行的Windows转换工具。


当前回答

iconv (1)

iconv -f FROM-ENCODING -t TO-ENCODING file.txt

此外,在许多语言中都有基于图标的工具。

其他回答

尝试+记事本

在Windows上,我能够使用notepad++从ISO-8859-1转换为UTF-8。点击“编码”,然后点击“转换为UTF-8”。

试试iconv Bash函数

我把它放到。bashrc中:

utf8()
{
    iconv -f ISO-8859-1 -t UTF-8 $1 > $1.tmp
    rm $1
    mv $1.tmp $1
}

..能够像这样转换文件:

utf8 MyClass.java

Visual Studio代码

Open your file in Visual Studio Code Reopen with Encoding: In the bottom status bar, to the right, you should see your current file encoding (eg "UTF-8"). Click this and select "Reopen with Encoding". Select the correct encoding of the file (eg: ISO 8859-2). Confirm that your content is displaying as expected. Save with Encoding: The bottom status bar should now display your new encoding format (eg: ISO 8859-2). Click this and choose "Save with Encoding" and select UTF-8 (or whatever new encoding you want).

注意:这将覆盖您的原始文件。先做备份。

DOS/Windows:使用代码页

chcp 65001>NUL
type ascii.txt > unicode.txt

可以使用chcp命令修改代码页。代码页65001是UTF-8的微软名称。设置代码页后,以下命令生成的输出将是代码页集。

如“如何纠正文件的字符编码?”Synalyze它!可以让你在OS X上轻松转换ICU库支持的所有编码。

此外,您还可以显示从所有编码转换为Unicode的文件的一些字节,以便快速查看哪个字节适合您的文件。