JS: Splitting a long string into strings with char limit while avoiding splitting words

前端 未结 4 1765
情深已故
情深已故 2021-01-04 02:37

I am trying to take a large block of text and split it into multiple strings that are 148 characters each, while avoiding cutting off words.

I have this now, which

4条回答
  •  情话喂你
    2021-01-04 03:31

    You are going to have to pad some of your strings, to make them have the number of characters you require.

    var lines= s.match(/(.{1,147}\s)\s*/g);
    

提交回复
热议问题