.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
sivanagamahesh

  

Insert word or characters at any position in a given string or sentence

   
 
     


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

Other Tutorials in the same Category:
      
  • How to find length or number of characters in a given string      
  • Compare two string using CompareTo Method of string class      
  • Check the word contains in a string or not?      
  • Merge or Concat two string value      
  • Check the string value Equals or not?      
  • Split the string based on delimiter and display or store      
  • Trim or remove white or extra spaces from given string      
  • Get the part or sub string from a given string      
  • Convert string into lowercase of a given string      
  • Convert all string into uppercase of a given string      
  • How to replace string with some other string value?      
  • Remove the specific character or word from a given string      
  • Insert word or characters at any position in a given string or sentence      
  • Display the reverse of the given string      
  • Find string, word or character in a given string      
  • Check the given string is null or empty

  •  
         
     
    Return to Main Index Page


    Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend