1

I am trying to create a function which sends a mail to the user. I am using MailMessage and sending a htmlbody back, and inside that the html body i want to insert some dynamically created data. My html is saved inside a string,

public static string HtmlBody = @"<html><body><p>Following mail contains the test results for the following test id {0}</p></body></html>";

since i am using @ i cant use string.format. My function works, meaning that the html is valid and i can send the email but i cant insert useful data inside the html.

zabse
  • 11
  • 2
  • `since i am using @ i cant use string.format` Why not? – Alejandro Aug 11 '21 at 13:07
  • Does this answer your question? [Long string interpolation lines in C#6](https://stackoverflow.com/questions/31764898/long-string-interpolation-lines-in-c6) – Alejandro Aug 11 '21 at 13:08
  • since i have placed ampersand in front of the string {0} is treated as a normal part of the string, and not as a special character. I tried to use string.format and it failed, due to aforementioned reasons. – zabse Aug 11 '21 at 13:09
  • 1
    You can easily mix both multiline and formatted strings, in both `string.Format` call and by adding $ before it. Look at the duplicate question for the details. – Alejandro Aug 11 '21 at 13:12
  • You should be able to use string.Format and interpolated strings, even with the @ sign, though interpolated strings require $ adding to the start of the string as well. In the event you can't get it working, use string.Replace to replace your placeholder with the information you want including in your final string. – LordPupazz Aug 11 '21 at 13:18
  • That would work, my original idea was to seperate the html string by placing it in a seperate static class, and acces it from the outside, and that way format the string. – zabse Aug 11 '21 at 13:33

0 Answers0