将一个字符串中单词之间的空格去掉,然后把每个单词首字母转换成大写
var str=" Vue is designed from the ground up to be incrementally adoptable. "
function formateStr(str){
var reg1 = /\b(\w)(\w*)\b/g;//全局匹配 单词
var d="" ;
str.replace(reg1,function($,$1,$2){
d+=$1.toUpperCase()+$2;
console.log($,$1,$2,$1.toUpperCase()+$2)
return $1.toUpperCase()+$2
});
return d
}
网友评论