简体   繁体   中英

how to append " in string in c#

for writing images on a html page i want to write only " after closing are anyone tell me about this then how i can write this

means to say that

<img src = " <% code is here %> " />

It can be done like this, by escaping the quote with \\"

String myStr = "Hello World";
myStr += "\"";

You can also use this syntax:

var s = @"a string with ""double quotes";
s += @"""";

If using variable or expression use this:

<% string imagePath = @"c:\Images\wallpaper.jpg"; %>
<img src = "<%=imagePath%> "/>

If using statement use this:

<img src = "<% 

    string imagePath = @"c:\Images\wallpaper.jpg";

    Response.Write(imagePath);

%>">
string s = "\"";

" is a special char. You need to prefix it with a \\ otherwise it will interprete the " as the end of the string.

Details here: http://blogs.msdn.com/csharpfaq/archive/2004/03/12/88415.aspx

To put double quotes into a string you have to escape them with a backslash. Eg:

String myString = "hello \" double quotes";

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