Search code examples
stringtypescriptnewlinestring-concatenation

How to concat string with new line character in typescript


I am trying to concat string and i want to put new line in the output string. I want to send the same string as email body using mailto so that i can display the string in multiple lines. when I put \n I could see in the dev console its printing with newline as formatted but, not in dom or in email body, i can'y use any html tags to break down to new line..any help here

input: line1line2line3line4line5;

I tried : "line1\nline2\nline3\nline4\nline5"

actual output: line1 line2 line3 line4 line5

expected output:
line1
line2
line3
line4
line5

Solution

  • You need to encode \n to pass it as url param %0A

    <a href="mailto:test@test.com?body=Hello%2CDear%0AText%0AText%0A" target="_blank">Email</a>

    If you are using javascript there is encodeURIComponent for that.