C# Insert Text Into a String – C# Programming Example
C# Console String Methods

C# Insert Text Into a String

Problem

You have a text (either a char or a string value) that needs to be inserted into a different string at a particular position.

Solution

The insert instance method of the String class makes it easy to insert a string or char into a string.

Below are the programs to illustrate the Insert() Method :

Example 1: C# Insert text in a String

In the string sourceString a second string is inserted between the characters > and <. The result is:

insert text into a string c#

 

Example 2: Insert space in string C#

Output:

insert text into a string c# 2

 

Example 3: C# add character to string at position, C# insert character into string every

 

Example 4: C# add to beginning of string

 

Example 5: C# append to end of string. C# add text to end of string

Output:

insert text end of string c#

 

Reference: https://msdn.microsoft.com/en-us/library/system.string.insert

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: