Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Escaping Quotes

Escaping Quotes

Scheduled Pinned Locked Moved C#
questiondatabase
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maliary
    wrote on last edited by
    #1

    Hi, I have values in my database that have quotes e.g Spanner 2",Tyre 12" I am working on escaping them so that the output to a CSV file is legible. Currently I have

    data = data.Replace("\"","\\\"");

    Which is not working because the \" is not there. Instead I have " without the slash. How can I escape them ?

    Let's do this !

    D P 2 Replies Last reply
    0
    • M maliary

      Hi, I have values in my database that have quotes e.g Spanner 2",Tyre 12" I am working on escaping them so that the output to a CSV file is legible. Currently I have

      data = data.Replace("\"","\\\"");

      Which is not working because the \" is not there. Instead I have " without the slash. How can I escape them ?

      Let's do this !

      D Offline
      D Offline
      dipak dipak
      wrote on last edited by
      #2

      Hello, You may replace the " char to any other char, like this data = data.Replace('"','\'); if you want to replace "(quote) to a string then you have to replace with a special character as above then u can replece that special char (as String) to any string. data = data.Replace('"','`'); // replacing old char to new char data = data.Replace("`","\\\"); // replaceing old String to new String It think u can solve your problem.. Best of Luck.

      Dipak

      1 Reply Last reply
      0
      • M maliary

        Hi, I have values in my database that have quotes e.g Spanner 2",Tyre 12" I am working on escaping them so that the output to a CSV file is legible. Currently I have

        data = data.Replace("\"","\\\"");

        Which is not working because the \" is not there. Instead I have " without the slash. How can I escape them ?

        Let's do this !

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        That should work. I just tried:

        string s = "12\" tire" ;

        System.Console.WriteLine ( s ) ;

        s = "\"" + s.Replace ( "\"" , "\\\"" ) + "\"" ;

        System.Console.WriteLine ( s ) ;

        And got

        12" tire
        "12\" tire"

        as expected. It's possible that the " character is not actually a " character, it could be some other Unicode character. (It could be Double Prime ″ Unicode 2033 for example.)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups