How to prevent Cropped words when use .match & .join

Hi 


I have a var with a huge string.
Am try to make a max letter count for each line.
Is work, but is cropped my word.

How i can prevent Cropped words ?
Like the red Arrow show..


Here how ma var are setup


I use this myvar=myvar.match(/.{1,40}/g).join(' \n ');


// The text string example in a var
var TempDesscr = 'this is a test with text.match, but is cropping';

// Now replace the same var with the '\n'for break line eatch 40 letters
TempDesscr=TempDesscr.match(/.{1,40}/g).join(' \n ');



// and show function for the text description in picture bitmap
$gameScreen.setDTextPicture('\\OW[6] ' + TempDesscr +' ', 36);
$gameScreen.setFont('GameFont');
$gameScreen.showPicture(894, '', 0, 660, 485, 100, 100, 255, 0);


nocrooping.png


Tanks a lot for helping guys
Try this:


TempDesscr=TempDesscr.match(/.{1,40}\b/g).join(' \n ');


The \b means a word boundary.

Original thread: https://forums.rpgmakerweb.com/threads/how-to-prevent-cropped-words-when-use-match-join.72165/