如何替换字符串中的特定单词?
如果要在此字符串中将SignInStatus result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);
替换为["hi", "hello", "welcome"]
。 (不区分大小写)
因此greetings
将变成Hi there Welcome hi
。
答案 0 :(得分:0)
按照示例
String.prototype.allReplace = function(obj) {
var retStr = this;
for (var x in obj) {
retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
}
return retStr;
};
var v = 'aabbaabbcc'.allReplace({'a': 'h', 'b': 'o'});