最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS字符串函數(shù)擴展代碼

 更新時間:2011年09月13日 22:29:32   作者:  
JS字符串函數(shù)擴展代碼,大家可以參考下prototype的使用方法,擴展自己的字符串處理函數(shù)。
復制代碼 代碼如下:

/****************************************************
*CreateBy:joe zhou
*CreateDate:2011-9-4
*Description:字符串輔助函數(shù)
****************************************************/
//String.prototype = {
// caption: function () {
// },
// leftPad: function (padChar, width) {
// if (this.length >= width) {
// return this;
// }
// }
//};
String.prototype.padLeft = function (padChar, width) {
var ret = this;
while (ret.length < width) {
if (ret.length + padChar.length < width) {
ret = padChar + ret;
}
else {
ret = padChar.substring(0, width-ret.length) + ret;
}
}
return ret;
};
String.prototype.padRight = function (padChar, width) {
var ret = this;
while (ret.length < width) {
if (ret.length + padChar.length < width) {
ret += padChar;
}
else {
ret += padChar.substring(0, width - ret.length);
}
}
return ret;
};
String.prototype.trim = function () {
return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
String.prototype.trimLeft = function () {
return this.replace(/^\s+/, '');
};
String.prototype.trimRight = function () {
return this.replace(/\s+$/, '');
};
String.prototype.caption = function () {
if (this) {
return this.charAt(0).toUpperCase() + this.substr(1);
}
return this;
};
String.prototype.reverse = function () {
var ret = '';
for (var i = this.length - 1; i >= 0; i--) {
ret += this.charAt(i);
}
return ret;
};
String.prototype.startWith = function (compareValue, ignoreCase) {
if (ignoreCase) {
return this.toLowerCase().indexOf(compareValue.toLowerCase()) == 0;
}
return this.indexOf(compareValue) == 0
};
String.prototype.endWith = function (compareValue, ignoreCase) {
if (ignoreCase) {
return this.toLowerCase().lastIndexOf(compareValue.toLowerCase()) == this.length - compareValue.length;
}
return this.lastIndexOf(compareValue) == this.length - compareValue.length;
};

相關(guān)文章

最新評論

托克托县| 宜昌市| 衡东县| 景泰县| 木里| 祁东县| 宝清县| 朝阳县| 甘德县| 壶关县| 和平县| 开平市| 历史| 荆门市| 运城市| 隆安县| 察隅县| 于都县| 恩施市| 海口市| 遵化市| 杨浦区| 安国市| 定襄县| 霍林郭勒市| 盈江县| 丁青县| 灵山县| 翼城县| 靖西县| 抚顺县| 城步| 临颍县| 朝阳县| 瑞丽市| 藁城市| 涟源市| 南皮县| 海安县| 金沙县| 镇原县|