📜  Node.js 操作系统.EOL

📅  最后修改于: 2022-05-13 01:56:27.320000             🧑  作者: Mango

Node.js 操作系统.EOL

os.EOL 常量是 os 模块的内置应用程序编程接口,用于获取操作系统指定的行尾字符或标记。

句法:

os.EOL

返回值:它返回运行它的操作系统指定的 EOL(行尾标记)。

下面的例子说明了在 Node.js 中os.EOL 常量的使用:

示例 1:

// Node.js program to demonstrate the   
// os.EOL constants
  
// Allocating os module
const os = require('os');
  
// Printing os.EOL character(s) by
// stringifying to JSON otherwise it
// will simply print as end of line
console.log(JSON.stringify(os.EOL));

输出:

"\r\n"

示例 2:

// Node.js program to demonstrate the   
// os.EOL constants
  
// Allocating os module
const os = require('os');
  
// Printing os.EOL character(s) with string
console.log("Paragraphs always contains EOL"
        + os.EOL + "EOL stands for end of line");
  
console.log("EOL varies from os to os" + os.EOL
            + "For windows it is \\r\\n" + os.EOL
            + "For POSIX it is \\n" + os.EOL);

输出:

Paragraphs always contains EOL
EOL stands for end of line
EOL varies from os to os
For windows it is \r\n
For POSIX it is \n

注意:以上程序将使用node index.js命令编译运行。

参考: https://nodejs.org/api/os.html#os_os_eol