开发者

strange characters at beginning of file

there are strange characters at the beginning of a file I'm editing (using textmate..) I don't know when they appeared, they're invisible in textmate but my script that reads the file goes crazy..

this is the first few chars in the file (as seen with od command):

0000000 177377 000120 000105 000117 000120 000114 000105 000072

the first 2 shouldn't be there I think.. maybe they were caused by some strange dropbox sync? Or开发者_开发百科 something else.. but they tend to reappear (I don't yet know when..)

My question: what is that 177377 and a simple way to remove it in my ruby script? thanks


The 000000 177377 (hex 0x0000FEFF) is a byte-order mark (BOM). It indicates to consumers that the remainder of the file is in big-endian UTF-32 encoding. This may not be correct in your case, but that's what the bytes indicate.

What to do with it is a little tricky. In general, the BOM does accurately represent the encoding of the following data. Detecting and skipping it and treating the subsequent content as if it were in your local default charset is usually going to be the wrong thing to do, even though it seems to be correct here. Instead, I'd try to figure out why your editor is inserting an incorrect BOM and whether there's a way to disable it.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜