我只使用原始 ANSI 标准中定义的 128 个字符集。
但总的来说,这些文件的实现方式有何不同。
我不关心显示,即如果一个选项卡显示为 6 或 8 个字符,但内存中的实际内部表示
我听说的一个区别是 \r\n (Windows) 与 \n 用于行终止(Linux)。
Ign*_*ams 20
Windows 上的“Unicode”是 UTF-16LE,每个字符为 2 或 4 个字节。Linux 使用 UTF-8,每个字符在 1 到 4 个字节之间。
“每个软件开发人员绝对、肯定必须了解 Unicode 和字符集的绝对最低要求(没有任何借口!)”
use*_*971 15
Windows 使用 CRLF ( \r\n
, 0D 0A
) 行尾,而 Unix 只使用 LF ( \n
, 0A
)。
Most modern (i.e., since 2004 or so) Unix-like systems make UTF-8 the default character encoding.
Windows, however, lacks native support for UTF-8. It internally works in UTF-16, and assumes that char
-based strings are in a legacy code page. Fortunately, Notepad is capable of reading UTF-8 files; unfortunately, "ANSI" encoding is still the default.
Windows (rarely) uses Ctrl+Z as an end-of-file character. For example, if you type
a file at the command prompt, it will be truncated at the first 1A
byte.
On Unix, Ctrl+Z is nothing special.
在 Windows 上,UTF-8 文件通常以“字节顺序标记”开头,EF BB BF
以区别于 ANSI 文件。
在 Linux 上,不鼓励使用 BOM,因为它会破坏 shell 脚本中的 shebang 行等内容。另外,当 UTF-8 是默认编码时,拥有 UTF-8 签名毫无意义。