The comprehensive guide of the dual quotation in the string of the rigidity in the string
In the string, the dual quotation number allows them to include them without damage the grammar. This guide explains in detail the method of achieving this purpose in C#.
Method 1: Words of word -by -word string
The word -by -word string is allowed to contain dual quotes in the string without righteousness in the string. They use "@" as the prefix:
Method 2: Royal character
<code class="language-csharp">string verbatim = @"He said to me, ""Hello World"". How are you?";</code>
or, you can use the back sloping bar character ('') to the dual quotation number:
Comparison
<code class="language-csharp">string escaped = "He said to me, \"Hello World\". How are you?";</code>
Example
In your example:
The word -by -word string is retained in the double quotation marks in the string, and the method of the rigid character is transferred to it:
Note:
<code class="language-csharp">@"He said to me, ""Hello World"". How are you?"</code>
In any case, the generated string contains only one double quotation marks. The double quotes have been righteous. The righteousness ensures that the dual quotes are explained as part of the string, not the string termination symbol.
The above is the detailed content of How to Escape Double Quotes in C# Strings?. For more information, please follow other related articles on the PHP Chinese website!