replace backslashes in string through JavaScript, / to \ - Javascript String Operation

Javascript examples for String Operation:String Replace

Description

replace backslashes in string through JavaScript, / to \

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <title></title> 
   </head> 
   <body> 
      <p id="p1">Original: </p> 
      <p id="p2">Modified: </p> 
      <script>
         var Str = '..\\..\\..\\folder\\folder';
          console.log(Str);
          document.getElementById('p1').innerHTML += Str;
         Str = Str.replace(/\\/gi,'/');
         console.log(Str);
          document.getElementById('p2').innerHTML += Str;
      //from www  .j  a  v  a 2 s  .c o  m
      </script>  
   </body>
</html>

Related Tutorials