title: Replace single quote with two single quotes in a string using c++
body: <p>The below function is working as expected. But I think I can do it in an efficient way. </p>
  
  <pre><code>input = "Hello' Main's World";
  </code></pre>
  
  <p>Function Return Value "Hello'' Main''s World";</p>
  
  <pre><code>string  ReplaceSingleQuote(string input)
  {
  
  int len = input.length();
  int i = 0, j =0;
  char str[255];
  sprintf(str, input.c_str()); 
  char strNew[255];
  
  for (i = 0; i &lt;= len; i++) 
  {
      if (str[i] == '\'') 
      {
          strNew[j] = '\'';
          strNew[j+ 1] = '\'';
          j = j + 2;
      } else
      {
          strNew[j] = str[i];
          j = j + 1 ;
      }
  }
  
  return strNew;
  
  }
  </code></pre>