C# - Program to add an extra ' where a ' is found
<p>I am working on something which adds a single quote ' for every ' found in the string. </p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
  class Program
  {
    static void Main(string[] args)
    {
        string insertStatement = "INSERT INTO EXCEPTION_LOG (value1, value2" +
                                    "VALUES ('test', 'test2');";

        AddEscapeStrings(insertStatement);
        Console.Read();
    }

    private static void AddEscapeStrings(string insertStatement)
    {
        int i = 0;
        char[] c = insertStatement.ToCharArray();

        while (i &lt; c.Length)
        {
            if (c.ElementAt(i) == '\'')
            {
                Console.Write(i + ", ");
                c[i - 1] = '\'';
            }

            i++;

            Console.WriteLine("\r\n ");

            for (int j = 0; j &lt; c.Length; j++ )
            {
                Console.Write(c.GetValue(j));
            }
        }            
    }
  } 
}
</code></pre>

<p>That piece of code is finding all the positions of the ', now I want to add an extra ' before it. However I am not sure which is the best way to do it, does c# have a method which adds a ' in the position required without replacing the current character at that position, or do I have to shift the array each time?</p>

<p>The desired result would be (note the double single quotes): </p>

<p>"INSERT INTO EXCEPTION_LOG (value1, value2" +
"VALUES (''test'', ''test2'');";</p>
