c# insert string into string code example

Example 1: insert variables into string c#

string data = "Mr. Rogers";
var str = $"Hello {data}, how are you doing?";

Example 2: insert variables into a string C#

// For Console.WriteLine() and Console.Write() do...

string var0 = "one";
string var1 = "two";
Console.WriteLine("{0} and {1}", var0, var1);

/* Outputs:

one and two

Example 3: c# insert character into string at position

//Insert method returns a copy, it does not alter the string since strings are immutable
string str = "abc";
str = str.Insert(2, "XYZ"); //str == "abXYZc"

Example 4: string.insert c#

public string Insert(int Indexvalue, string value)

Tags:

Cpp Example