javascript: how do I pass safe strings to an array for client side display without messing it up / ASP.NET C#
<p>platform: ASP.NET 3.5 / C#</p>

<p>My requirement is this:</p>

<p>I want to create a rather large array on the server side (in C#) and pass it to the browser via </p>

<pre><code>Page.ClientScript.RegisterArrayDeclaration("gBank", js);
</code></pre>

<p>My array is a 2-dimension array, and I am constructing it right to pass it to the client. Simple cases work fine.</p>

<p>My problem is the content of the array - there are several strings, for e.g.</p>

<pre><code>[[4, 'hello there', 'this is \n one'],[5,'again','there's another string']] etc. 
</code></pre>

<p>These strings can have new lines, ',- and other such characters including &lt; > etc. I did a replace '\n' with '\n' and that was fine, but other characters like ' mess up the array string in the client side.</p>

<p>How do I pass these strings 'safely' so that the array is not messed on the client side, and the content displays as-is?</p>

<hr>

<p>I found this code on Rick Stahl's blog</p>

<p><a href="http://www.west-wind.com/weblog/posts/114530.aspx" rel="nofollow">http://www.west-wind.com/weblog/posts/114530.aspx</a></p>

<p>and it seems to work pretty well.</p>
