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.
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.
xxxxxxxxxx
1
using System;
2
3
public class StringUtils
4
{
5
public static void Main(string[] args)
6
{
7
String text = "ABCD";
8
String substring = text.Substring(1);
9
10
Console.WriteLine(substring); // BCD
11
}
12
}
Output:
xxxxxxxxxx
1
BCD
The range operator ..
is used to make a slice of the collection.
xxxxxxxxxx
1
using System;
2
3
public class StringUtils
4
{
5
public static void Main(string[] args)
6
{
7
String text = "ABCD";
8
String substring = text[1..];
9
10
Console.WriteLine(substring); // BCD
11
}
12
}
Output:
xxxxxxxxxx
1
BCD