Insert variable values in the middle of a string

后端 未结 6 1980
生来不讨喜
生来不讨喜 2020-12-05 03:56

In C#: If I want to create a message like this: \"Hi We have these flights for you: Flight A,B,C,D. Which one do you want\"

where just the section i

6条回答
  •  生来不讨喜
    2020-12-05 04:43

    1 You can use string.Replace method

    var sample = "testtesttesttest#replace#testtesttest";
    var result = sample.Replace("#replace#", yourValue);
    

    2 You can also use string.Format

    var result = string.Format("your right part {0} Your left Part", yourValue);
    

    3 You can use Regex class

提交回复
热议问题