首页 > 代码库 > js替换字符串

js替换字符串

js替换最后一次出现的匹配的字符串

var v = "abbbabbbbab";        var pos = v.lastIndexOf("a");        var vv = v.substring(0, pos) + "c" + v.substring(pos+1, v.length);        alert(vv);

js直接替换第一次出现的匹配字符串

var str = "adksdjfldjfoeoxl";var t = str.lastIndexOf("d");str = str.replace(/d/, "c");alert(str);

 

js替换字符串