4

According to several answers here on SO, eg. How can I detect the encoding/codepage of a text file it is not possible to retrieve the encoding of a file.

How does VS do it then? If I "Save as", and select "Save with encoding" it shows the current encoding of my file.

Community
  • 1
  • 1
Vindberg
  • 1,502
  • 2
  • 15
  • 27
  • 3
    When Saving, VS (or any other Editor) _determines_ the encoding. Detection is needed when Opening a file. – H H Nov 16 '11 at 09:18
  • Yes, but when you start saving VS has **detected the current encoding** correctly. The question is how it does just that, not how it saves... – Pleun Nov 16 '11 at 09:30
  • 1
    Im starting to think that VS isn't detecting anything and may be using the default system encoding for files that doesn't have a [BOM](http://unicode.org/faq/utf_bom.html#bom1) or other kind of marker... – Vindberg Nov 16 '11 at 09:36
  • 3
    If there is no BOM, all bets are off. – leppie Nov 16 '11 at 09:40
  • Check if [this](http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/7a9decde-25c1-439e-8110-212eed64f371/) is a solution to your problem – Illuminati Nov 16 '11 at 09:24

1 Answers1

1

By default, the editor detects encoding by searching for byte order marks or charset tags. If neither is found in the current document, the code editor attempts to auto-detect UTF-8 encoding by scanning byte sequences. VS Help

If VS fails to convert any byte sequences to valid unicode symbols, it opens file in default system character set. No magic realy.

NekoNaz
  • 181
  • 6