您的位置:首页 > Web前端 > JavaScript

javascript 扩充String类型的函数功能

2007-07-03 14:29 375 查看
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(); }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐