How to convert from an encoding to UTF-8 in Go?

前端 未结 4 796
臣服心动
臣服心动 2020-12-30 06:23

I\'m working on a project where I need to convert text from an encoding (for example Windows-1256 Arabic) to UTF-8.

How do I do this in Go?

4条回答
  •  一个人的身影
    2020-12-30 07:26

    I made a tool for myself, maybe you could borrow some idea from it :)

    https://github.com/gonejack/transcode

    This is the key code:

    _, err = io.Copy(
        transform.NewWriter(output, targetEncoding.NewEncoder()),
        transform.NewReader(input, sourceEncoding.NewDecoder()),
    )
    

提交回复
热议问题