close

用.replace("要被置換的字","要換成的字")

只會置換第一個

若要置換全部,必須用//g (golobal)

Ex: 

var test = "B1 B2 S1/S2//End";
console.log(test);

=>結果: B1 B2  S1/S2//End

test = test.replace(" ", "-").replace("/", "-");
console.log(test);

=>結果: B1-B2  S1-S2//End

test = test.replace(/ /g, "-").replace(/\//g, "-");
console.log(test);

=>結果:B1-B2--S1-S2--End

 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 sendohlun 的頭像
    sendohlun

    廣度與深度

    sendohlun 發表在 痞客邦 留言(0) 人氣()