我想搜索地址字符串。
如果找到“ Southeast”,则将其替换为“ SE”;
如果找到“西南”,则将其替换为“西南”;
如果找到“东北”,则将其替换为“NE”;
如果找到“东北”,则将其替换为“西北”。
这是我到目前为止所做的:
var searchStr = [" Southeast ", " Southwest ", " Northeast ", " Northwest "];
var replaceStr = [" SE ", " SW ", " NE ", " NW "];
var oldAddress = $("#address").text();
for (i=0;i<searchStr.length;i++){
var n = oldAddress.match(/this[i]/g);
if(n != null){
$("#address").text(replaceStr[i]);
}
}
它什么也没做,我错过了什么吗?