Word Wrap
Word Wrap //JavaScript Repository //+ Jonas Raoni Soares Silva //@ http://jsfromhell.com/string/wordwrap [rev. #2] //+ Jonas Raoni Soares Silva //@ http://jsfromhell.com/string/wordwrap [rev. #2] String.prototype.wordWrap = function(m, b, c){ var i, j, l, s, r; if(m m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")) j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length; return r.join("\n"); }; Định dạng hàm: String.wordWrap(maxLength: Integer, [breakWith:String="\n"], [cutType:Integer = 0]): String Kết quả: Returns an string with the extra characters/words "broken". maxLength: maximum amount of characters per line breakWtih: string that will be added whenever it's needed to break the line cutType: 0 = words longer than "maxLength" will ...