Escaping from C #, a little puzzled

I feel stupid asking such a question. How to avoid double quotes?

I tried Google and it says to use \ "but it does not work.

string html = @"<a href=\"http://google.com\">Test</a>";

He returns

';' expected

What am I doing wrong?

+3
source share
1 answer

One of them:

string html = "<a href=\"http://google.com\">Test</a>";
string html = @"<a href=""http://google.com"">Test</a>";

Evasion varies between two forms. The second, with the prefix "@", is known as a literal string literal , allows line breaks, etc. And does not consider the backslash as a special escape character. Thus, it processes everything except the double quote without the need for escaping - and the double quote escapes, doubling it, so it is not interpreted as the end of a string literal.

+12
source

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


All Articles