Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 253
betafish Avatar asked Aug 14 '09 15:08

betafish


People also ask

Why does \n not work in JavaScript?

Your question is not clear but if you mean why "\n" is not visible as text in js then it is because it is newline character i.e it can be used to get an similar effect as html <br> tag.

What is the newline character in notepad?

This character is commonly known as the 'Line Feed' or 'Newline Character'. CR (character : \r, Unicode : U+000D, ASCII : 13, hex : 0x0d) : This is simply the 'r' character. This character is commonly known as 'Carriage Return'.

How do you put a line break in a script?

To create a line break in JavaScript, use “<br>”.


2 Answers

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

like image 118
Robert Greiner Avatar answered Sep 18 '22 22:09

Robert Greiner


You can use the following:

text += "\r\n";
like image 24
searlea Avatar answered Sep 21 '22 22:09

searlea