asp.net - How can I include a newline in a constant in C# -


i have code sends email message users on registration:

await usermanager.sendemailasync(2, "confirm account",                  "please confirm account clicking link: <a href=\"www.cnn.com\">link</a>"); 

this works want lot more advanced , have seen many templates out there. templates out there @ least 100 lines long , have newlines after every line. here's example of when tried adding 1 new line.

await usermanager.sendemailasync(2, "confirm account",              "please confirm account clicking link:               <a href=\"www.cnn.com\">link</a>"); 

as have new line message saying cannot include new line in constant.

can suggest way include this?

there 3 issues here. first if have lot of text, shouldn't including in source code directly anyway. small localizable pieces of text, can use resx/resources file - visual studio present grid can specify text particular resource name etc.

for lots of text, however, i'd consider creating .txt file embed assembly, , read assembly.getmanifestresourcestream. it's much easier edit text file manage large blocks of string literals.

the rest of answer, however, addresses question asked, string literals.

second getting line break string, can done either including directly using escape sequences:

await usermanager.sendemailasync(2, "confirm account",      "please confirm account clicking link:\r\n<a href=\"www.cnn.com\">link</a>"); 

(here \r\n carriage return , line feed. may want \r or \n. depends on context.)

or verbatim string literal:

await usermanager.sendemailasync(2, "confirm account",      @"please confirm account clicking link:       <a href=""www.cnn.com"">link</a>"); 

note in verbatim string literal, need escape double-quotes doubling them, backslash backslash.

but give line break in html. if you're trying line break in displayed text, should use html. example, could use:

await usermanager.sendemailasync(2, "confirm account",      "please confirm account clicking link:<br /><a href=\"www.cnn.com\">link</a>"); 

... gather <br> tag out of favour - should @ other ways of controlling layout of html. remember linebreak in html unlikely relevant in page.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -