javascript 扩充String类型的函数功能

 


String.prototype.trim  = function(){ return this.replace(/(^[\s]*)|([\s]*$)/g, "");

String.prototype.ltrim = function(){ return this.replace(/(^[\\s]*)/g, ""); }
String.prototype.rtime = function(){ return this.replace(/([\\s]*$)/g, ""); }

String.prototype.realLength = function(){ return this.replace(/[^\\x00-\\xff]/g,"**").length; }//计算字符串的长度,一个汉字两个字符
//功能:检测是否为空或NULL值

String.prototype.isNullOrEmpty = function() { return this.trim().realLength() < 1 ? true : false; }
String.prototype.toLower = function() { return this.toLowerCase(); }
String.prototype.toUpper = function() { return this.toUpperCase(); }

原文地址:https://www.cnblogs.com/lovemory/p/804286.html