public Insert ( int index, bool value ) : StringBuilder | ||
index | int | |
value | bool | |
return | StringBuilder |
StringBuilder sb = new StringBuilder("world"); sb.Insert(0, "hello "); Console.WriteLine(sb); // output: "hello world"
StringBuilder sb = new StringBuilder("The quick brown fox jumps over the lazy dog."); sb.Insert(20, "red "); Console.WriteLine(sb); // output: "The quick brown red fox jumps over the lazy dog."
StringBuilder sb = new StringBuilder("123456789"); for (int i = 2; i < sb.Length; i += 3) { sb.Insert(i, ","); } Console.WriteLine(sb); // output: "12,34,56,78,9"These examples demonstrate how the Insert method can be used to modify a StringBuilder object in various ways. The System.Text namespace is the package library in which the StringBuilder class belongs.