[Webinar] Learn how to a build a cloud-first strategyRegister Now


Get Encoding From byte array

Posted on 2005-04-06
Medium Priority
Last Modified: 2008-01-09
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 !
Question by:software22

Accepted Solution

xmstr earned 2000 total points
ID: 13715972
try checking for a byte order mark using the UTF8Encoding.GetPreamble method, see msdn link:


LVL 10

Expert Comment

ID: 13767207
If there is no preamble you can just guess. May be there is a field in the http header indicating the encoding.

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question