Free C# Tutorials

home
Stay at Home and Learn

The Insert Method in C# .NET

 
Computer Tutorials List

 

 

 

 

 

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.

 

 

 

<-- IndexOf | PadLeft and PadRight in C# -->

<--Back to the C# .NET Contents Page

View all our Home Study Computer Courses