Amol
Amol

Reputation: 127

how do Insert "#" in a c# string variable?

Does anybody know how to insert "#" in a c# string variable? Is there any escape sequence for this kind of thing? for e.g.

string myString = "<li><a href="#1">Image 1</a><li>";

Upvotes: 1

Views: 127

Answers (4)

Amol
Amol

Reputation: 127

Paddy was right. There was no need to escape [#]. I only had to escape ["]. It works fine now. Thanks Paddy and everyone else who responded.

Upvotes: -1

TGH
TGH

Reputation: 39258

string myString = "<li><a href='#1'>Image 1</a><li>";

It's better to use single quotes in attributes inside a c# string to avoid the escaping

Upvotes: 0

Amit Singh
Amit Singh

Reputation: 8109

string myString = @"<li><a href=""#1\"">Image 1</a><li>";

Upvotes: 1

Raptor
Raptor

Reputation: 54222

Try:

string myString = "<li><a href=\"#1\">Image 1</a><li>";

You have to escape the double quotes.

Upvotes: 4

Related Questions