How To Remove The Last X Characters From A String Using C#



TODO:

Have you ever wanted to remove the last X characters from a string in C#?

 

SOLUTION:

string foo = "1234567890abcd";
string bar = foo.Substring(foo.Length - 4);

 

NOTES:

The example above will remove the last 4 characters from foo, and store the result in bar.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading