tags:

views:

66

answers:

1

Hi

Is there a way to convert UTF-8 string to Chinese Simplified (GB2312) in C#. Any help is greatly appreciated.

Regards Jyothish George

+1  A: 

The first thing to be aware of is that there's no such thing as a "UTF-8 string" in .NET. All strings in .NET are effectively UTF-16. However, .NET provides the Encoding class to allow you to decode binary data into strings, and re-encode it later.

Encoding.Convert can convert a byte array representing text encoded with one encoding into a byte array with the same text encoded with a different encoding. Is that what you want?

Alternatively, if you already have a string, you can use:

byte[] bytes = Encoding.GetEncoding("gb2312").GetBytes(text);

If you can provide more information, that would be helpful.

Jon Skeet