Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6574379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:15:13+00:00 2026-05-25T15:15:13+00:00

I am working on something which adds a single quote ‘ for every ‘

  • 0

I am working on something which adds a single quote ‘ for every ‘ found in the string.

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 < c.Length)
        {
            if (c.ElementAt(i) == '\'')
            {
                Console.Write(i + ", ");
                c[i - 1] = '\'';
            }

            i++;

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

            for (int j = 0; j < c.Length; j++ )
            {
                Console.Write(c.GetValue(j));
            }
        }            
    }
  } 
}

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?

The desired result would be (note the double single quotes):

“INSERT INTO EXCEPTION_LOG (value1, value2” +
“VALUES (”test”, ”test2”);”;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:15:14+00:00Added an answer on May 25, 2026 at 3:15 pm

    Maybe I’m missing something but why not simply use the Replace method?

    insertStatement = insertStatement.Replace("'","''"); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am now working on a program for Android which is something related to
I'm working on a thread library which implement user level threads (i have something
I'm working on something that was built on a PC set-up using php and
I'm working on something that requires traversing through the file system and for any
I am using Linq to SQL to call a stored procedure which runs a
I've been using IronPython for a while now, but something which really hampers my
I'm working on something that pulls in urls from delicious and then uses those
I'm working on something of a wizard-type application to allow users to build simple
So I'm working on something in obj-c (I'd rather not say what) where I
I am willing to develop a mobile application. I wish to have something working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.