Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert line break after every 80 characters

Tags:

javascript

I have a very long string.

I want to append <br/> after every 80 characters so it can displayed nicely in the inner HTML.

Is there any easy way?

like image 947
anas Avatar asked Jul 27 '13 06:07

anas


People also ask

How do you insert a line break character?

Double-click on the cell in which you want to insert the line break (or press F2). This will get you into the edit mode in the cell. Place the cursor where you want the line break. Use the keyboard shortcut – ALT + ENTER (hold the ALT key and then press Enter).

How do I force a line break in a text box?

Of course, there are situations in which there is need to add line breaks. You can do so by simply hitting Shift + Return or Shift + Enter , respectively.


Video Answer


1 Answers

Do it with long_string.replace(/(.{80})/g, "$1<br>");

Check it here: http://jsfiddle.net/x2YJp/

like image 191
chris-l Avatar answered Oct 17 '22 20:10

chris-l