简体   繁体   中英

how do Insert “#” in a c# string variable?

Does anybody know how to insert "#" in ac# string variable? Is there any escape sequence for this kind of thing? for eg

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

Try:

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

You have to escape the double quotes.

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

最好在ac#string内的属性中使用单引号以避免转义

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM