Languages
[Edit]
EN

C#/.NET - remove characters from string

3 points
Created by:
Nabila-Burnett
385

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
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.
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