Re: Finding out a file encoding

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Morten Wennevik (MortenWennevik_at_hotmail.com)
Date: 09/07/04


Date: Tue, 07 Sep 2004 09:30:34 +0200

Hi Gaia,

You should do

byte[] p = Encoding.Unicode.GetPreamble();
And then test the first bytes in your file against these bytes for each possible encoding.

This may work for unicode encoded files since I believe they add a mark to the file to specify endianess. However, you are not guaranteed to detect the file encoding this way because

1: The encoding may not have an identifying mark.
2: Your file may not have an identifying mark.

I don't think any ANSI encoded files have an identifying mark.

-- 
Happy Coding!
Morten Wennevik [C# MVP]


Relevant Pages

  • Re: requestEncoding = "ISO-8859-1"
    ... "Mark" is far to bland. ... I placed the META tag in the HTML form file. ... I need to pick an encoding that is capable of representing the ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: KOREAN LANGUAGE NOT FULLY UNINSTALLED
    ... I forgot to mention the encoding issue. ... >> Mark L. Ferguson ... >> marfers notes for windows xp ... >>> Thanks, victor ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: oe6 reading mail showing as html raw source?
    ... Open Outlook ... > Is there a check mark to use default encoding for all incoming messages? ... > native support for Unicode so if you are using some other type of encoding ... it on the working accounts to see if I could make them fail, no luck. ...
    (microsoft.public.windows.inetexplorer.ie6_outlookexpress)
  • RE: Symbols and characters instead of English
    ... With your internet explore open click view at the top on the tool bar and then click encoding and put a check mark beside automatic. ...
    (microsoft.public.windowsxp.general)