-2

I'm struggling with escape characters in C#.

I'm saving a varchar field in a SQL Server database with a quote that needs to be escaped. So, an example could be something like that: (\"value\")

When my frontend application consume this value from API I get the value with a single escape character as i have in the DB.

The problem come up when consuming this API from C# code. For some reason this single character (\) is replaced for three of them (\\\).

After debugging the code I found that when I retrieve the data I get this:

debugging the value

When I click to check the value it seems OK:

Value into Text Visualizer

My question is why theese two extra backslashes are added and how can I get rid of them in order to get only one => (\").

Hope anyone can help me :)

Thanks!

Diego
  • 1
  • Please show your code – Jonathan Oct 19 '20 at 23:22
  • The easiest way to add backslash is to just add one. Could be a practical joke by one of your friends/coworkers. If you suspect less a foul play and more of an error in coding - please review [MCVE] guidance on posting code/input/output and [edit] post accordingly. – Alexei Levenkov Oct 19 '20 at 23:23
  • The debugger always shows the strings as they would be as non-verbatim literals in code. Which means that characters like \ and " are escaped. See duplicate. – Peter Duniho Oct 19 '20 at 23:25
  • 1
    Don't do it. Bind your sql parameters. – Jeremy Lakeman Oct 19 '20 at 23:37

1 Answers1

-1

You value should be correct. The debugger window escape the “/“, therefore it appears like escape(backslash)escape(quote). (//)(/“)

Wei J. Zheng
  • 249
  • 2
  • 8
  • That's correct, but the problem is that I am getting theese three backslashes if I consume this service from postman or for another service. – Diego Oct 19 '20 at 23:37