Introduction : In this tutorial is used to insert the desired string or word in the middle of the sentence using Insert() method of string class of .NET framework using C# and VB.NET code sample.
Insert() method of string class is used to insert the word or string in any where in the sentence.
Insert() Method will take the initial index of the character position in the string or sentence where and you want to insert in desired word.
C# code example: using System;
namespace DotNetSparkTutorials
{
class Program
{
static void Main(string[] args)
{
// Declare string;
string strValue = "DotNetSpark";
// Insert the word or string in a given string);
string strResultValue = strValue.Insert(11, ".com");
//Display the resultant sub string which stored in variable strResultValue2
Console.WriteLine(strResultValue);
Console.ReadLine();
}
}
}
Output:
DotNetSpark.com
VB.NET sample example Namespace DotNetSparkTutorials
Class Program
Private Shared Sub Main(args As String())
' Declare string;
Dim strValue As String = "DotNetSpark"
' Insert the word or string in a given string);
Dim strResultValue As String = strValue.Insert(11, ".com")
'Display the resultant sub string which stored in variable strResultValue2
Console.WriteLine(strResultValue)
Console.ReadLine()
End Sub
End Class
End Namespace
Output:
DotNetSpark.com |