Replace Quote with Escape and Quote

A dumb question, probably, but can't seem to get it to work. I need to Replace the quotes from the text box with \ "so that it exports correctly. I'm trying:

[Note].Text).Replace("\"", "\"") 

Am I doing this completely wrong? I won’t be surprised if I will. Any recommendations on how to do this?

Thanks!

+6
source share
6 answers
 String quotedText = "\"Hello, world!\""; // quotedText = "Hello, World!" String newQuotedText = quotedText.replace("\"", "\\\""); // newQuotedText = \"Hello, World!\" 

You need to avoid the backslash that you want to transfer to the new value.

+12
source

.Replace("\"", "\\\"")

\\ means the character \ . You should also avoid this, so it can be shown.

+2
source

You need to avoid the backslash as well as the quote:

 mystring.Replace("\"", "\\\"") 
+1
source
 Replace("\"", "\\\""); 

You need 3 \ for the replacement string, the first to avoid the second, so that \ appears in the field, and the third to avoid quotes

0
source

It works

 string s = "diana\"s here"; string s2=s.Replace ("\"","\\\""); 
0
source

Lazy, but I'm pretty sure it works.

 Replace("\"","\\" + "\""); 
0
source

Source: https://habr.com/ru/post/905539/


All Articles