📜  javascript 在 x 个字符后拆分文本 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:05.645000             🧑  作者: Mango

代码示例1
// =======( /.{4}/g  ) Replace number 4 number the any the number for cout the char 
// this will add space after each charactar  
// ========= (index % 40 == 36 ? '\n' : ' ') spose you have 100 characater thrn
//this line will add new line after each 40 character..


var replaced = str.replace(/.{4}/g, function (value, index) {
    return value + (index % 40 == 36 ? '\n' : ' ');
});