How do I create a new line using javascript that shows correctly in notepad?

自作多情 提交于 2021-02-18 09:55:51

问题


I have a script that copies table cells from the browser into the user's clipboard. I loop through each cell and when a new line is needed I use

text += "\n";

If I paste the text into excel, it formats correctly and fills in the proper rows, however if I paste into notepad, it shows a symbol instead of creating a new line:

123□456□789

instead of:

123

456

789

Is there something else I can use that notepad will recognize as a line break?


回答1:


that's because you need a carriage return and line feed.

text += "\r\n";

The non programming way
open up in WordPad
save
open in notepad




回答2:


You can use the following:

text += "\r\n";



回答3:


In my case, \r\n was not working with double qoutes " but instead single qoute ' did the job like

 text += '\r\n';


来源:https://stackoverflow.com/questions/1278501/how-do-i-create-a-new-line-using-javascript-that-shows-correctly-in-notepad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!