String replace in javascript -


so have string var total_res = r4-4r4-5; , want replace r4-5 substring "",but have tried code far , doesn't work:

javascript:

<script>    $(document).ready(function(){         ss = "r4-5";         lool = total_res.replace(ss,"");         alert(lool);//it alerts same original string    });     </script> 

what wrong? thank help.

i'm not sure if meant or not, total_res should declared string...like:

var total_res = "r4-4r4-5"; 

using code, works that:

http://jsfiddle.net/rv8cb/

if checked browser's (error) console, you'd see: unexpected token illegal.

note .replace() replaces first occurrence of string. you'd have use regular expression if want replace every occurrence of "r4-5" in string.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -