- 将字符串中小写数字转换成数组中大写数字(我的QQ号哦~)
var str = "839243680";
var ary = ["〇","一","二","三","四","五","六","七","八","九"];
str = str.replace(/\d/g,function(){
return ary[arguments[0]];
});
console.log(str); // --> 八三九二四三六八〇
- 写一个函数,清空字符串前后的空格(兼容所有浏览器)
tips: 字符串有个trim函数,但是不支持IE7/8
方案一:
if(!String.prototype.trim){
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, "");
};
}
方案二:
function myTrim(str){
if(typeof trim == "function"){
return str.trim();
}else{
return str.replace(/(^\s*)|(\s*$)/g, "");
}
}