V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
MrEatChicken
V2EX  ›  程序员

请教,有没有工具能将 GB2312 的代码文件转 UTF8

  •  
  •   MrEatChicken · 2022-02-28 14:49:48 +08:00 · 2405 次点击
    这是一个创建于 785 天前的主题,其中的信息可能已经有所发展或是发生改变。

    试了下直接转编码格式,中文会乱码 有没有工具可以统一转下,中文也能正常显示。 谢谢各位

    12 条回复    2022-03-04 16:13:20 +08:00
    cooleggs
        1
    cooleggs  
       2022-02-28 15:00:00 +08:00
    vscode 不就可以么,so easy
    BrettD
        2
    BrettD  
       2022-02-28 15:00:18 +08:00 via iPhone   ❤️ 1
    iconv
    knightdf
        3
    knightdf  
       2022-02-28 15:05:35 +08:00   ❤️ 1
    iconv +1
    unishare
        4
    unishare  
       2022-02-28 15:06:11 +08:00
    有可以批量转的吗
    likeunix
        5
    likeunix  
       2022-02-28 15:12:36 +08:00
    Ctrl+C and Ctrl+V
    jim9606
        6
    jim9606  
       2022-02-28 15:15:47 +08:00   ❤️ 1
    命令行 iconv ,支持任意方向的编码转码。
    xuanbg
        7
    xuanbg  
       2022-02-28 16:42:56 +08:00
    vscode 可以用 GB2312 编码打开,然后保存为任意编码
    AllenHua
        8
    AllenHua  
       2022-02-28 17:15:04 +08:00
    啊这,np++ 也可
    imn1
        9
    imn1  
       2022-02-28 17:31:16 +08:00
    单文件现代编辑器基本都可以,打开再同名另存选编码就行
    批量的也有不少工具,搜搜就见到
    shawndev
        10
    shawndev  
       2022-02-28 17:33:02 +08:00
    iconv
    MrEatChicken
        11
    MrEatChicken  
    OP
       2022-02-28 17:35:28 +08:00   ❤️ 1
    感谢各位,已经用 iconv 了,写了个 shell 脚本
    有需要的可以拿去用

    #! /bin/bash
    function read_dir(){

    #iconv *.h -f GB2312 -t UTF-8 -o *.h
    for file in `ls $1` #注意此处这是两个反引号,表示运行系统命令
    do
    if [ -d $1"/"$file ] #注意此处之间一定要加上空格,否则会报错
    then
    echo menu $1"/"$file
    read_dir $1"/"$file
    else
    if [ "${file##*.}"x = "h"x ]||[ "${file##*.}"x = "cpp"x ];then #只转.h 和.cpp 的文件
    iconv $1"/"$file -f GB2312 -t UTF-8 -o $1"/"$file #GB2312 转换 UTF-8
    echo $1"/"$file
    fi
    fi
    done
    }
    #读取第一个参数
    read_dir $1
    dcncy
        12
    dcncy  
       2022-03-04 16:13:20 +08:00
    @unishare 试试这个工具 UltraCodingSwitch ,非常强。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3578 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 48ms · UTC 11:03 · PVG 19:03 · LAX 04:03 · JFK 07:03
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.