在前一篇文章中《文件编码格式的转换之GB2312转UTF-8 Without BOM》:
https://blog.csdn.net/cpdoor2163_com/article/details/112260222
提到了几种GB2312转UTF-8的方法,这里还可以使用iconv完成GB2312转UTF-8的任务:
“iconv命令可以将一种已知的字符集文件转换成另一种已知的字符集文件。”
两句题外话:
WPS中,如果写入过中文,存储的表格csv文件就是GB2312编码格式的。WPS里不能存储为UTF-8格式。才有了写这2篇文章的起因。
要想知道文件的编码格式,除了记事本,VS等专业的一点的工具,QQ浏览器(QQ Browser),和Firefox浏览器,这些常用的浏览器,可以查看文件的编码格式,不过需要删除文件的后缀名。
iconv的Windows版的下载地址:
《LibIconv for Windows》
http://gnuwin32.sourceforge.net/packages/libiconv.htm
或者,在这里也可以下载,iconv的Windows版:
https://download.csdn.net/download/cpdoor2163_com/14038792
GB2312转UTF-8的方法步骤:
1.
创建ConverFile_From_GB2312_To_UTF8WithoutBOM.bat,内容如下:
iconv.exe -f GB2312 -t UTF-8 Table1_GB2312.csv > Table1_UTF8WithoutBOM.csv
从Table1_GB2312.csv生成了Table1_UTF8WithoutBOM.csv,可以看到把GB2312文件转为UTF-8 Without BOM编码格式了。
参考:
a.
《libiconv》
http://www.gnu.org/software/libiconv/
b.
《使用windows命令和iconv.exe批量转换文件编码》
https://www.cnblogs.com/adgnat/archive/2011/07/15/2107884.html
c.
《iconv》
https://baike.baidu.com/item/iconv/524310?fr=aladdin
d.
iconv help:
Usage: iconv.exe [OPTION...] [-f ENCODING] [-t ENCODING] [INPUTFILE...]
or: iconv.exe -l
Converts text from one encoding to another encoding.
Options controlling the input and output format:
-f ENCODING, --from-code=ENCODING
the encoding of the input
-t ENCODING, --to-code=ENCODING
the encoding of the output
Options controlling conversion problems:
-c discard unconvertible characters
--unicode-subst=FORMATSTRING
substitution for unconvertible Unicode characters
--byte-subst=FORMATSTRING substitution for unconvertible bytes
--widechar-subst=FORMATSTRING
substitution for unconvertible wide characters
Options controlling error output:
-s, --silent suppress error messages about conversion problems
Informative output:
-l, --list list the supported encodings
--help display this help and exit
--version output version information and exit
Report bugs to <bug-gnu-libiconv@gnu.org>.
e.
《Unicode 和 UTF-8、UTF-16、UTF-32之间的关系》
https://blog.csdn.net/hongsong673150343/article/details/88584753