EN
C# / .NET - remove prefix from string
0 points
In this article, we would like to show you how to remove prefix from string in C#.
Quick solution:
xxxxxxxxxx
1
string text = "ABC-123";
2
int prefixLength = 4;
3
4
text = text.Substring(prefixLength);
5
6
Console.WriteLine(text); // Output: "123"
In this example, we use Substring()
method to remove first 4
letters from the text
string.
xxxxxxxxxx
1
using System;
2
3
public class TestClass
4
{
5
public static void Main()
6
{
7
string text = "ABC-123";
8
int prefixLength = 4;
9
10
text = text.Substring(prefixLength);
11
12
Console.WriteLine(text);
13
}
14
}
Output:
xxxxxxxxxx
1
123