今天發現巨好用工具EditPlus,批量轉換文件編碼格式
文檔(Document)菜單——文件編碼(File encoding)——批量轉換編碼(File encoding multiple),選中全部文件後轉碼,然後再全部保存
最近將windows下的代碼移到linux平臺,發現linux下對中文支持的不好,導致代碼文件裏中文註釋部分全爲亂碼,
因此,在移到linux平臺前將普通的dos代碼文件批量轉換爲UTF-8格式文件。
這裏採用perl處理:
use strict;
use warnings;
use Encode;
open(IN, "<", "test.dos");
open(OUT, ">", "test.utf8");
while(<IN>){
chomp();
my $line = Encode::decode("gb2312", $_); # 必須知道文件的原始編碼格式
$line = Encode::encode("UTF-8", $line);
print OUT "$line\n";
}
close(IN);
close(OUT);
如果覺得本文對你有所幫助,可以請我喝杯茶哈 ^-^