Administrator
Administrator

Reputation: 116

How to convert strings from "GBK" to "UTF-8" in C#?

I come up against problem when I develop my email client.I find the name of the email attachment in Chinese is messy code when I send an email with attachment which name include Chinese from my app to the email server and get if back from the server.But it is right at the email server.In addition,when I send an email with attachment which name include Chinese from the other client,it's all Ok. Thank you for all!

Upvotes: 1

Views: 4363

Answers (1)

JackWang
JackWang

Reputation: 311

do you mean the string is stored in a byte array?

        string strSource = "abcdefg";
        byte[] array2=Encoding.GetEncoding("gbk").GetBytes(strSource);

        //get string from gbk
        string str = Encoding.GetEncoding("gbk").GetString(array2);

        //convert string to utf-8
        byte[] array3 = Encoding.UTF8.GetBytes(str);

=================answer is edited below, 2016.08.01=============

You should read the chinese name of the attach with gbk, then you forword the email content to other place use utf-8 or gbk. you could have a try and test.

Upvotes: 2

Related Questions