1、字符串替换
String.prototype.replaceAll = function(src,desc){
return this.replace(new RegExp(src,"gm"),desc);
}
正则表达式中:g=global,m=multiLine
2、去左右空格
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
3、排序
function sort(){
var numbers=[1,3,5,7,9,2,4,6,8,0];
numbers.sort();
}
4、倒置
function sort(){
var numbers=[1,3,5,7,9,2,4,6,8,0];
numbers.reverse();
}
5、字符串连接
var StringBuffer=function(){
this.strings=[];
}
StringBuffer.prototype.append=function(str){
return this.strings.push(str);
}
StringBuffer.prototype.toString=function(){
return this.strings.join("");
}
2313

被折叠的 条评论
为什么被折叠?



