Languages
[Edit]
EN

C#/.NET - remove characters from string

3 points
Created by:
Marcin
15740

In C#/.NET it is possible to remove string characters with String.Remove method.

1. Remove last character example

string text = "abc";
//string result = text.Remove(text.Length - 1, 1);
string result = text.Substring(0, text.Length - 1);
Console.WriteLine(text);

Output:

ab

2. Remove all characters after character position example

string text = "abc";
string result = text.Remove(1);
Console.WriteLine(result);

Output:

a

3. Remove all characters between character positions example

String text = "abc";
String result = text.Remove(1, 1);
Console.WriteLine(result);

Output:

ac

4. References

  1. String.Remove - Microsoft Docs
  2. String.Substring - Microsoft Docs
Native Advertising
50 000 ad impressions - 449$
🚀
Get your tech brand or product in front of software developers.
For more information contact us:
Red dot
Dirask - friendly IT community for everyone.

❤️💻 🙂

Join