Introduction:

In this article we will explain how to use string Remove method or what is string Remove method in c# with example.

Description:

In c# programming language Remove() method is a string method, the Remove method is used to deletes a specified number of characters from a specified position in a string.  

In case, if we want to delete a particular length of substring, then we need to specify the starting position and length of characters to delete from the given string.

 

C# Remove Method Example

Following is the example of using string Remove() method to delete a characters in string based on the defined position in c# programming.

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace SQLTutorialsPoint
{
    class Program
    {
        static void Main(string[] args)
        {
            string msg = "Welcome to SQL"; 
            Console.WriteLine("Remove Result: {0}", msg.Remove(5)); 
            Console.WriteLine("Remove with Length: {0}", msg.Remove(3, 7)); 
            Console.WriteLine("\nPress Enter Key to Exit.."); 
            Console.ReadLine();
        }
    }
}

 

As you see above example, we used a string Remove() method to remove a characters starting from the position 5 till the end of defined string and another Remove() method to delete a 7 characters starting from the position 3.


When we execute above c# program, we will get the result like as shown below.

 

 How to use String Remove Method in C#

 

As you see above result, the string Remove() method has deleted a characters based on the defined positions and returned a remaining string characters.

 

In this article we have learned, how we can use string Remove() method to delete a required characters from the given string based on the defined position in c# programming language.

 

I hope it will help to you after reading.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

You may also like