Skip to main content

Remove Method of string in C# Explained

Remove Method of string in C#

The string Remove method is used to delete characters in the string starting from the specified position and continues to the end of the 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.

 

Remove Method Syntax

Following is the syntax for defining a string Remove method to remove characters starting from the defined position in a given string.

 

public string Remove(int startIndex)

public string Remove(int startIndex, int length)

 

Given the above syntaxes, the first syntax is used to delete all the characters in the string, starting from the defined position (startIndex) and the second syntax is used to delete particular length of a substring by defining the starting position and length of characters.

Remove Method Example

The following code snippets is the example of using a string Remove() method to delete characters in string based on the defined position.

 

using System;

namespace CsharpnaijaTutorial

{

    class Program

    {

        static void Main(string[] args)

        {

            string msg = "Welcome to Csharpnaija";

            Console.WriteLine($"Remove Result: {msg.Remove(5)}");

            Console.WriteLine($"Remove with Length: {msg.Remove(3, 7)}");

            Console.WriteLine("\nPress Enter Key to Exit..");

            Console.ReadLine();

        }

    }

}

 

From the 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 7 characters starting from the position 3.

 

When you execute the above program, you will get the result as shown below.

 

Remove out


 

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

 

Thank you

 

References

1.     Tutlane

2.     MicrosoftDocumentation

3.     Geeksforgeeks


Comments

  1. GameStop Games and Games on PS5, Xbox One,
    In 메리트 카지노 the spirit of retro gaming, GameStop has 더킹카지노 도메인 announced 우리 바카라 the new games coming to หาเงินออนไลน์ PS5 카지노 안전 사이트 and Xbox One. With more games coming to the service, the

    ReplyDelete

Post a Comment

Popular posts from this blog

The String.Join Method in C# Explained

The String.Join Method in C#   The string.Join concatenates the elements of a specified array or the members of a collection, using the specified separator between each element or member. Overloads of string.Join Method Description Join(Char, Object[]) Concatenates the string representations of an array of objects, using the specified separator between each member. Join(Char, String[]) Concatenates an array of strings, using the specified separator between each member. Join(String, IEnumerable<String>) Concatenates the members of a constructed IEnumerable<T> collection of type String, using the specified separator between each member. Join(String, Object[]) Concatenates the elements of an object array, using the specified separator between each element. Join(String, String[]) Concatenates all the elements of a string array, usi...

Classes in C# Explained

C# Class Explained A class is nothing but an encapsulation of properties and methods that are used to represent a real-time entity, as explained by Guru99 . For instance, if you want to work with Guest’s data as in our previous DataDriven Web application . The properties of the Guest would be the Id, GuestName, Address, Phone number etc of the Guest. The methods would include the entry and modification of Guest data. All of these operations can be represented as a class in C# as shown below. using System; namespace CsharpnaijaClassTutorial {     public class Guest     {         public int Id { get ; set ; }         public string GuestName { get ; set ; }         public string Address { get ; set ; }         public string WhomToSee { get ; set ; }     ...

Most Popular Programming Languages in 2020

Most Popular Programming Languages in 2020 In this blog post, you will learn about the most popular programming languages in 2020 for creating the best web applications. Check its pros and cons. Analyzed by technostacks Not very long ago, just a few people were considered to be computer programmers, and the general public viewed them with awe. In this digital age that we are now living in, however, a large number of IT jobs need a solid grasp of one or more programming languages. Whether one wants to develop a mobile app or get a certification for having programming knowledge, or even to learn new skills, one needs to opt for the right programming language. Below mentioned eight most popular programming languages which are in demand for software development and web applications. This is the most used programming languages in 2019 and will be in 2020. For each, there is little information about the language, benefits and its complexity, as well as about its usage. One must...