The Insert Method in C# .NET

The Insert Method in C# .NET

The Insert method is, not surprisingly, used to insert characters into a string of text. You use it like this:
string someText = "Some Text";
someText = someText.Insert( 5, "More " );
In between the round brackets of Insert, you need two things: A position in your text, and the text you want to insert. A comma separates the two. In our code above, the position that we want to insert the new text is where the T of "Text" currently is. This is the fifth character in the string (the count starts at zero). The text that we want to Insert is the word "More".

Exercise
Test out the code above, for the Insert( ) method. Have one message box to display the old text, and a second message box to display the new text.

Comments