开发者

How does Windows Notepad interpret characters?

I was wondering how Windows interprets characters.

I made a file with a hex editor with the 3 bytes E3 81 81.

Those bytes are the character in UTF-8.

I opened the notepad and it displayed . I didn't specify the encoding of the file, I just created the bytes and the notepad interpreted it co开发者_如何转开发rrectly.

Is notepad somehow guessing the encoding?

Or is the hex editor saving those bytes with a specific encoding?


If the file only contains these three bytes, then there is no information at all about which encoding to use.

A byte is just a byte, and there is no way to include any encoding information in it. Besides, the hex editor doesn't even know that you intended to decode the data as text.

Notepad normally uses ANSI encoding, so if it reads the file as UTF-8 then it has to guess the encoding based on the data in the file.

If you save a file as UTF-8, Notepad will put the BOM (byte order mark) EF BB BF at the beginning of the file.


Notepad makes an educated guess. I don't know the details, but loading the first few kilobytes and trying to convert them from UTF-8 is very simple, so it probably does something similar to that.


...and sometimes it gets it wrong... https://ychittaranjan.wordpress.com/2006/06/20/buggy-notepad/


There is an easy and efficient way to check whether a file is in UTF-8. See Wikipedia: http://en.wikipedia.org/w/index.php?title=UTF-8&oldid=581360767#Advantages, fourth bullet point. Notepad probably uses this.

Wikipedia claims that Notepad used the IsTextUnicode function, which checks whether a patricular text is written in UTF-16 (it may have stopped using it in Windows Vista, which fixed the "Bush hid the facts" bug): http://en.wikipedia.org/wiki/Bush_hid_the_facts.


how to identify the file is in which encoding ....?

Go to the file and try to Save As... and you can see the default (current) encoding of the file (in which encoding it is saved).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜