/**
* 是否以某一字符串开头
* @param s
* @returns {boolean}
*/
String.prototype.startWith = function (s) {
if (s == null || s == "" || this.length == 0 || s.length > this.length)
return false;
if (this.substr(0, s.length) == s)
return true;
else
return false;
return true;
}
/**
* 是否以某一字符串结尾
* @param s
* @returns {boolean}
*/
String.prototype.endWith = function (s) {
if (s == null || s == "" || this.length == 0 || s.length > this.length)
return false;
if (this.substring(this.length - s.length) == s)
return true;
else
return false;
return true;
}
/**
* 是否存在于参数字符串列表中
* @returns {boolean}
*/
String.prototype.isStrEquals = function () {
let args = arguments
if (isObjNull(args) || args.length == 0) {
return false
} else {
for (let i = 0; i < args.length; i++) {
let arg = args[i]
if (isObjNull(arg)) {
return false
}
if (this === arg) {
return true
}
}
return false
}
}
/**
* 字符串全局替换
* @param reg
* @param s
* @returns {string}
*/
String.prototype.replaceAll = function (reg, s) {
if (isObjEmpty(this)) {
return ''
}
return this.replace(new RegExp(reg, 'gm'), s)
}
网友评论