Double quote string replace in C#

后端 未结 6 623
野性不改
野性不改 2020-12-05 09:15

How to replace the below string in C#

Current:

\"John K \"GEN\" Greg\"

The Goal:

 \"John K \\\"GEN\\\" Greg\"
         


        
6条回答
  •  一个人的身影
    2020-12-05 09:53

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

    What are you escaping it for? If you're going to insert it into DB, consider using prepared statements instead. If you're going to use it in your HTML output, consider using some template engine that does it for yourself instead.

提交回复
热议问题