How to encode and decode chinese characters?
Posted
by
melaos
on Stack Overflow
See other posts from Stack Overflow
or by melaos
Published on 2012-06-10T09:59:52Z
Indexed on
2012/06/10
10:40 UTC
Read the original article
Hit count: 177
I've try googling around but wasn't able to find what charset that this text below belongs to:
具有éœé›»ç”¢ç”Ÿè£ç½®ä¹‹å½±åƒè¼¸å…¥è£ç½®
But putting <meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
and keeping that string into a html file i was able to view the chinese character wording properly.
which is:
???????????????
So my question is:
what tools can i use to detect the character set of those text?
And how do i convert/encode/decode them properly in C#?
Updates: Added some test code
[TestMethod]
public void TestMethod1()
{
string encodedText = "具有éœé›»ç”¢ç”Ÿè£ç½®ä¹‹å½±åƒè¼¸å…¥è£ç½®";
Encoding encoder = new UTF8Encoding();
byte[] postBytes = encoder.GetBytes(encodedText);
postBytes = UTF8Encoding.Convert(Encoding.UTF8, Encoding.Unicode, postBytes);
string decodedText = Encoding.Unicode.GetString(postBytes);
Assert.AreNotEqual(encodedText, decodedText);
}
thanks
© Stack Overflow or respective owner