Search code examples
c#stringstring-interpolation

How do I interpolate strings?


I want to do the following in C# (coming from a Python background):

strVar = "stack"
mystr  = "This is %soverflow" % (strVar)

How do I replace the token inside the string with the value outside of it?


Solution

  • string mystr = string.Format("This is {0}overflow", strVar);
    

    And you could also use named parameters instead of indexes.