GibboK
GibboK

Reputation: 73918

Problem with String Verbatim

I use C#.

I need assign a value to a string as verbatim.

Here my code:

string verbatim = "@<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">";

or

string verbatim = @"<META NAME=""ROBOTS"" CONTENT=""NOINDEX, NOFOLLOW"">";

But it does not work.

What I'm doing wrong here? Thanks

Upvotes: 2

Views: 209

Answers (3)

Strillo
Strillo

Reputation: 2972

The @ must be outside the string and you need to use double quotes:

string verbatim = @"<META NAME=""ROBOTS"" CONTENT=""NOINDEX, NOFOLLOW"">";

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1062780

You mean a verbatim string literal? Double-up the internal quotes and move the @:

string verbatim = @"<META NAME=""ROBOTS"" CONTENT=""NOINDEX, NOFOLLOW"">";

Upvotes: 4

Digbyswift
Digbyswift

Reputation: 10400

The @ charctaer goes outside the string ath beginning and you need to escape your quotes, i.e.

string verbatim = @"<META NAME=""ROBOTS"" CONTENT=""NOINDEX, NOFOLLOW"">"

Upvotes: 3

Related Questions