Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using @ symbol in string

Tags:

c#

asp.net

This link says that:

The @ symbol tells the string constructor to ignore escape characters and line breaks.

I try to append contain in StringBuilder like this.

   StringBuilder sb = new StringBuilder();
   sb.Append(@"<test name="test_all">");

But it gives an error in test_all.

I got a solution for this using single quotes. ' ':

sb.Append("<test name='layout_all'>");

But I don't understand as per document why " " does not work. Or am I missing something to understand?

like image 518
4b0 Avatar asked Dec 19 '12 10:12

4b0


People also ask

Can a string have symbols?

Explanation: Given string contains alphabets, number, and special characters.

How do I print a symbol with string?

We can print the string using %s format specifier in printf function. It will print the string from the given starting address to the null '\0' character.

How do I find a symbol in a string?

The strchr() function finds the first occurrence of a character in a string. The character c can be the null character (\0); the ending null character of string is included in the search. The strchr() function operates on null-ended strings.


1 Answers

Well, " still has a special meaning in a verbatim string literal - you need to escape it, but in this case, you simply double it:

sb.Append(@"<test name=""test_all"">");
like image 68
Oded Avatar answered Sep 21 '22 10:09

Oded