javascript - How to insert a newline character after every 200 characters with jQuery -
i have textbox use insert information. want insert newline character after every 200 characters using jquery or javascript.
for instance:
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
in example, want insert newline chracter after every 200 characters. how can this?
break string after every 200 characters, add newline, , repeat process remaining string:
function addnewlines(str) { var result = ''; while (str.length > 0) { result += str.substring(0, 200) + '\n'; str = str.substring(200); } return result; }
Comments
Post a Comment