// 一,用正则表达式来将字符串"I? love ?? the ?great ? ?wall in ?beijing"
// 更改为:"I love the Great Wall in Beijing",主要是为了解决编码的问题导致的问题,规律:
// 1,乱码只有两种特殊字符分别是'?'和' ';
// 2,如果乱码的末尾是'?'则它的下一位字母肯定是大写;
function stringReg(text) {
this.text = text;
this.getString = function () {
const regArr = this.text.match(/[\?][a-z]/g);
for (var i = 0; i < regArr.length; i++) {
var UpperCase = regArr[i][1].toUpperCase()
this.text = this.text.replace(regArr[i], UpperCase)
}
return this.text
};
this.trim = function () {
this.text = this.text.replace(/\s\s*/g, ' ')
};
this.delSymbol = function () {
this.text = this.text.replace(/\?/g, "");
};
this.init = function getString() {
this.getString()
this.delSymbol()
this.trim()
};
this.init()
console.log(this.text)
return this.text
}
new stringReg("I? love ?? the ?great ? ?wall in ?beijing")