title: Replace backslashes in a string using Java/Groovy
body: <p>Trying to get a simple string replace to work using a Groovy script.  Tried various things, including escaping strings in various ways, but can't figure it out.</p>
  
  <pre><code>String file ="C:\\Test\\Test1\\Test2\\Test3\\"
  String afile = file.toString() println
  "original string: " + afile
  afile.replace("\\\\", "/")
  afile.replaceAll("\\\\", "/") println
  "replaced string: " + afile
  </code></pre>
  
  <p>This code results in:</p>
  
  <pre><code>original string: C:\Test\Test1\Test2\Test3\
  replaced string: C:\Test\Test1\Test2\Test3\
  </code></pre>
  
  <h2>----------------------------</h2>
  
  <p>The answer, as inspired by Sorrow, looks like this:</p>
  
  <pre><code>  // first, replace backslashes
    String afile = file.toString().replaceAll("\\\\", "/")
    // then, convert backslash to forward slash
    String fixed = afile.replaceAll("//", "/")  
  </code></pre>