How do I interpolate strings?

前端 未结 15 768
感情败类
感情败类 2020-11-27 05:38

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

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

How do I

15条回答
  •  感情败类
    2020-11-27 05:52

    You have 2 options. You can either use String.Format or you can use the concatenation operator.

    String newString = String.Format("I inserted this string {0} into this one", oldstring);
    

    OR

    String newString = "I inserted this string " + oldstring + " into this one";
    

提交回复
热议问题