Search code examples
c#asp.netstring-concatenation

Concatenating To A Verbatim String Literal With Large Volume Of Text Breaking Into New Line


how do I concatenate a variable within a verbatim string literal with large volume of text breaking into newlines? I am using a stringbuilder to append all the string variables but

What I intend doing -

StringBuilder sbuilder = new StringBuilder();
variable y = something
variable x = @"text"+ y + "
             other text other text";
variable z = @"blablabla";
variable z2 = @"some other text"

sbuilder.Append(x);
sbuilder.Append(z);
sbuilder.Append(z2);

string html = sbuilder.ToString();

What I tried -

var variable = modelview.something; 
string form = @"a whole lotta text "+variable+ "even more text";

I was getting syntax errors

Represents text as a series of Unicode characters.To browse the .NET framework source code for this type, see the Reference Source.
Newline in constant

Solution

  • Maybe something like this is what you are looking for.

    string myVar = "hello";
    string form = $@"My String {myVar}";