EN
C# / .NET - remove first character from string
0
points
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