Get Encoding From byte array

Posted on 2005-04-06
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
    LVL 3

    Accepted Solution

    try checking for a byte order mark using the UTF8Encoding.GetPreamble method, see msdn link:

    LVL 10

    Expert Comment

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

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    754 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

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now