考慮,下面的代碼:在Node.js中有什麼方法在控制檯上打印 n r?
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
輸出:
This is my text.
And other information.
How to console.log
?
我怎麼能與\n
安慰,\r
& \n\r
?
考慮,下面的代碼:在Node.js中有什麼方法在控制檯上打印 n r?
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(myVar);
輸出:
This is my text.
And other information.
How to console.log
?
我怎麼能與\n
安慰,\r
& \n\r
?
我發現自己使用JSON.stringify
來打印這樣的東西。
代碼:
console.log(JSON.stringify("i am a string!\nwith some newlines\r\n!"));
輸出:
"i am a string!\nwith some newlines\r\n!"
得到了一些solution:
代碼:
var myVar = 'This is my text.\nAnd other information.\rHow to console.log\n\r?';
console.log(require('util').inspect(myVar, { showHidden: true, depth: null }));
console.log('----------------');
console.log('Just console.log');
console.log(myVar);
輸出:
This is my text.\nAnd other information.\rHow to console.log\n\r?
----------------
Just console.log
This is my text.
And other information.
How to console.log
?
其它方式也受到了歡迎。
據我知道,如果你輸出你的console.log一些特殊字符
例如:%實際上是控制檯日誌的控制字符,您必須將其編碼爲:%25
因爲%C做你的輸出的CSS格式化,作爲一個例子
的換行符將不被顯示爲這樣