且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何清理不可见字符的源代码文件?

更新时间:2023-02-20 08:15:46

您在编辑器中找不到该字符,因为您在文本编辑器中找不到它.#FEFF 或 #FFFE 是所谓的字节顺序标记.它们是 Microsoft 的发明,用于在 Unicode 文件中说明多字节字符的存储顺序.

You don't get the character in the editor, because you can't find it in text editors. #FEFF or #FFFE are so-called byte-order marks. They are a Microsoft invention to tell in a Unicode file, in which order multi-byte characters are stored.

要摆脱它,请告诉您的编辑器将文件保存为 ANSI/ISO-8859 或 Unicode 无 BOM.如果您的编辑器不能这样做,您将不得不切换编辑器(可悲的是)或使用某种截断工具,例如十六进制编辑器,它允许您查看文件真正看起来.

To get rid of it, tell your editor to save the file either as ANSI/ISO-8859 or as Unicode without BOM. If your editor can't do so, you'll either have to switch editors (sadly) or use some kind of truncation tool like, e.g., a hex editor that allows you to see how the file really looks.

在谷歌搜索中,TextWrangler 似乎有一个UTF-8,没有 BOM".模式.否则,如果您对终端感到满意,则可以使用 Vim:

On googling, it seems, that TextWrangler has a "UTF-8, no BOM" mode. Otherwise, if you're comfortable with the terminal, you can use Vim:

:set nobomb

并保存文件.快点!

在文本文件中,字符总是最先.正如我提到的,支持 BOM 的编辑器根本不会向您展示.

The characters are always the very first in a text file. Editors with support for the BOM will not, as I mentioned, show it to you at all.