js 字符串常用操作
function Class_String_Common(){
//将字符串 myString 的 start位置 和 end位置 之间的内容替换为 replaceStr
this.replace1 = function(start,end,myString,replaceStr,callback){
if(!replaceStr){
return callback(myString);
}else{
var j = myString.substring(start+1,end);
var s = myString.replace(j,replaceStr);
return callback(s);
}
}
//全局替换
this.replaceAll = function(myString,oldStr,newStr,callback){
if(!myString || !oldStr || !newStr){
return callback(myString);
}else{
// var s = myString.replace("\/"+oldStr+"\/g", newStr);
var s = myString.replace(new RegExp(oldStr,"gm"), newStr);
return callback(s);
}
}
}
module.exports = Class_String_Common;