linux与windows字符编码格式的自动调整

这几天频繁在windows和ubuntu下调试代码,字符编码格式不同老是造成很大的困扰,windows下的默认字符编码格式是GBK(gb2312)而在ubuntu下的是utf-8。前天光来回的保存编码格式就费了很大的劲,今天google了下找到了个临时还算是不错的方法。

ubuntu下自带一个字符编码格式调整命令:iconv

[cpp]  view plain  copy
  1. ICONV(1)                       Debian GNU/Linux                       ICONV(1)  
  2.   
  3. NAME  
  4.        iconv - Convert encoding of given files from one encoding to another  
  5.   
  6. SYNOPSIS  
  7.        iconv -f encoding [-t encoding] [inputfile]...  
  8.   
  9. DESCRIPTION  
  10.        The iconv program converts the encoding of characters in inputfile, or  
  11.        from the standard input if no filename is specified, from one coded  
  12.        character set to another. The result is written to standard output  
  13.        unless otherwise specified by the --output option.  
  14.   
  15.        --from-code, -f encoding  
  16.               Convert characters from encoding.  
  17.   
  18.        --to-code, -t encoding  
  19.               Convert characters to encoding. If not specified the encoding  
  20.               corresponding to the current locale is used.  
  21.   
  22.        --list, -l  
  23.               List known coded character sets.  
  24.   
  25.        -c     Omit invalid characters from output.  
  26.   
  27.        --output, -o file  
  28.               Specify output file (instead of stdout).  
  29.   
  30.        --silent, -s  
  31.               Suppress warnings, but not errors.  
  32.   
  33.        --verbose  
  34.               Print progress information.  
  35.   
  36.        --help, -?  
  37.               Give help list.  
  38.   
  39.        --usage  
  40.               Give a short usage message.  
  41.   
  42.        --version, -V  
  43.               Print program version.  
  44.   
  45. ENCODINGS  
  46.        The values permitted for --from-code and --to-code can be listed by the  
  47.        iconv --list command, and all combinations of the listed values are  
  48.        supported. Furthermore the following two suffixes are supported:  
  49.   
  50.        //TRANSLIT  
  51.               When the string "//TRANSLIT" is appended to --to-code,  
  52.               transliteration is activated.  This means that when a character  
  53.               cannot be represented in the target character set, it can be  
  54.               approximated through one or several similarly looking  
  55.               characters.  
  56.   
  57.        //IGNORE  
  58.               When the string "//IGNORE" is appended to --to-code, characters  
  59.               that cannot be represented in the target character set will be  
  60.               silently discarded.  
  61.   
  62.   
  63. AUTHOR  
  64.        iconv was written by Ulrich Drepper as part of the GNU C Library.  
  65.   
  66.        This man page was written by Joel Klecker <espy@debian.org>, for the  
  67.        Debian GNU/Linux system.  
  68.   
  69.   
  70. 3rd Berkeley Distribution            lenny                            ICONV(1)  

通过上面的介绍估计大家就可以很好的理解了。

iconv -f gb2312 -t utf-8 a.txt > b.txt;

 就可以将字符编码为gb2312的文件a.txt转换到编码格式为utf-8的b.txt文件。这样就可以在ubuntu下正常的查看了。希望可以帮到大家,自己也留底备用。


如果是在windows下,可以使用word来修改字符编码,但是比较麻烦,有一个小软件:convert比较好用,能批量式修改。大家可以搜一下。我也上传了一个到资源区,大家可以下载:http://download.csdn.net/detail/timebomb/3987420


  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值