C# String.Insert() technique: Here, we will find out about the Insert() strategy for String class with example.
C# String.Insert() Method
String.Insert() technique is utilized to embed a string in a presence string at the determined record and returns another string.
Syntax:
public string String.Insert(int index, string value);
The strategy is called with “this” string, for example, the string where we need to embed the string.
Parameter(s):
- list – speaks to the record/position of the present string where new string an incentive to be embedded.
- value – another string to be embedded.
- Return value:
- string – it restores another string containing the embedded string at given file.
Example:
Input:
string str = "JustTechReview";
string str1 = " programming ";
Function call
str.Insert(7, str1);
Output:
JustTech programming Review
C# Example to change over the string to characters exhibit utilizing String.Insert() technique:
Example 1:
using System;
class JustTechReview
{
static void Main()
{
// declaring string variables
string str = "JustTechReview";
// inserting space between JustTech and Review
string new_string = str.Insert(7, " ");
Console.WriteLine("str: " + str);
Console.WriteLine("new_string: " + new_string);
}
}
Output:
str: JustTechReview
new_string: JustTech Review
Example 2:
using System;
class JustTechReview
{
static void Main()
{
// declaring string variables
string str = "JustTechReview";
string str1 = " programming ";
// inserting str1 after "JustTech"
string new_string = str.Insert(7, str1);
Console.WriteLine("str: " + str);
Console.WriteLine("new_string: " + new_string);
}
}
Output:
str: JustTechReview
new_string: JustTech programming Review