Node.js examples for String:sub string
Get substring from String
String.prototype.sub = function(n){ var r = /[^\x00-\xff]/g; if (this.length <= n){ return this.toString(); }//w ww .j av a 2 s . c o m if(this.replace(r, "mm").length <= n) return this.toString(); var m = n;//Math.floor(n/2); for(var i=m; i<this.length; i++) { if(this.substr(0, i).replace(r, "mm").length>=n) { return this.substr(0, i) + "..."; } } return this.toString(); };