How to insert a <CR> (Carriage Return) in a Javascript String?
10,366
In ES6 with string templates you just introduce the carriage return as written text.
Also you can use \n
to mark carriage return in quoted strings.
const str = `l
e`;
console.log(str);
const str2 = 'l\ne';
console.log(str2);
Author by
LaPregunta
Updated on June 09, 2022Comments
-
LaPregunta almost 2 years
I need to insert a Carriage Return in a String. As far as I know the
\r
should do it but here is the problem:I wrote this in the browser console:
1\r2
then I get:12
in return. Now I copy/paste it on Notepad++ https://imgur.com/a/pUW8pThere is a CR and a LF there. How I can add just a CR?
Note that you can replace the LF(\n) in notepad, save the file and the LFs are gone.
-
Mardoxx over 6 yearsWhy do you want this?
-
lumio over 6 yearsProbably Notepad++ added an LF by itself.
-
LaPregunta over 6 yearsi make a CSV file and send it via Email, the line delimiters must be <CR> only.
-
trincot over 6 yearsDo you know you can change the line delimiter to CR only in notepad++? Menu Edit - EOL Conversion - Old Mac Format.
-
LaPregunta over 6 yearsYes, but that does not modify the file, just the way that you look at it in notepad++
-