Escape char problem while generating JavaScript page through Java code?
<p>I am generating <a href="http://en.wikipedia.org/wiki/JavaScript" rel="nofollow">JavaScript</a> pages through <a href="http://en.wikipedia.org/wiki/Java%5F%28programming%5Flanguage%29" rel="nofollow">Java</a> code like:</p>

<pre><code>FileOutputStream fs=new FileOutputStream("C:\\Documents and Settings\\prajakta\\Desktop\\searcheng.html");
OutputStreamWriter out=new OutputStreamWriter(fs);
out.write("&lt;script language='JavaScript' type='text/javascript'&gt;");
out.write("var str=new String('C:\\Documents and  Settings\\prajakta\\Desktop\\substr.html');");
out.write("var beg=str.lastIndexOf('\\');");//double' \' **Problem Stmt**
</code></pre>

<p>And so on.</p>

<p>The problem is when searcheng.html is created it contains</p>

<pre><code>var beg=str.lastIndexOf('\');//single '/'
</code></pre>

<p>which creates a problem in finding index of '\'.
How should I write this problem so that it will contain double "\"?</p>

<p>Similarly how should I write a statement </p>

<pre><code>out.write("document.write('&lt; a href='str'&gt; '+str.slice(beg+1,end)+' &lt;/a&gt;');");
</code></pre>

<p>so that it will create statement in JavaScript as </p>

<pre><code>document.write('&lt; a href=" 'str' "&gt;  '+str.slice(beg+1,end)+'  &lt;/a&gt;');
</code></pre>

<p>and the link will go to page whose address is stored in <code>str</code>?</p>
