Languages
[Edit]
EN

C# / .NET - remove first character from string

0 points
Created by:
Trenton-McKinney
618

In this article, we would like to show you how to remove the first character from the string in C# / .NET.

 

1. Using String substring() method

In the example below, we use the String Substring(int beginIndex) method, where we assign 1 to beginIndex, so we get a string without the first character.

using System;

public class StringUtils
{
    public static void Main(string[] args)
    {
        String text = "ABCD";
        String substring = text.Substring(1);

        Console.WriteLine(substring); // BCD
    }
}

Output:

BCD

2. Using range operator ..

The range operator .. is used to make a slice of the collection.

using System;

public class StringUtils
{
    public static void Main(string[] args)
    {
        String text = "ABCD";
        String substring = text[1..];

        Console.WriteLine(substring); // BCD
    }
}

Output:

BCD

Reference

  1. Substring() method - .NET Docs
  2. Range operator - .NET Docs
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - remove first character from string

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join