Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add line breaks after n numbers of letters in long words

A have a string that can reach up to 100 characters in lenght. Is there an easy way to insert line breaks in the word every 10th letter? For example:

aaaaaaaaaaaaaaaaaaaaaaaaa

Should turn in to

aaaaaaaaaa<br/>aaaaaaaaaa<br/>aaaaa

I know that i can modify html with the html() method, but im not sure how to count characters and insert the tags. Thanks

like image 892
Johan Avatar asked May 29 '12 12:05

Johan


1 Answers

Here is one option:

string.match(/.{1,10}/g).join("<br/>");
like image 124
VisioN Avatar answered Sep 27 '22 23:09

VisioN