• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1228
  • Last Modified:

Get Encoding From byte array

In my app, HTML is downloaded from server an stream to a byte array. But I don't know how to detect its encoding. Encoding of these html can be iso8859-1 or UTF-8.

My code :

byte[] objDataArray = ...

System.Text.UTF8Encoding objEncoding = new System.Text.UTF8Encoding();
string strData = objEncoding.GetString(objDataArray);

-- > if encoding of html is iso8859-1, strData will not correct

Please help me !
0
software22
Asked:
software22
1 Solution
 
xmstrCommented:
try checking for a byte order mark using the UTF8Encoding.GetPreamble method, see msdn link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemtextutf8encodingclassgetpreambletopic.asp

-x
0
 
ptmcompCommented:
If there is no preamble you can just guess. May be there is a field in the http header indicating the encoding.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now