Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Add Non Escape Double Quotes to a String in .NET

0.00/5 (No votes)
24 Jun 2015 3  
Adding double quotes to string variable is easy with StringBuilder in .NET.

Introduction

I see several posts on a lot of sites with people trying to create strings with embedded double quotes. This can be easily achieved with string builder in .NET.

Using the Code

The trick is to use a StringBuilder to and wrap the double quote within two single quotes.

The example below builds a string fragment for building a SQL for Oracle with uses double quotes to surround field names (TSQL uses []).

StringBuilder sb = new StringBuilder();
            var col = "Name Col";
            sb.Append('"' + col + '"');
            sb.Append(" = @NAME ");

History

  • 24-Jun-2015: Created

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here