For .NET Framework
public static class Extensions
{
public static string TrimLastCharacter(this string sender) =>
string.IsNullOrWhiteSpace(sender) ?
sender :
sender.TrimEnd(sender[sender.Length - 1]);
}
For .NET Framework Core 5 (Here note the ^1 which targets the last character in the string ^ is know as a hat.
public static class Extensions
{
public static string TrimLastCharacter(this string sender) =>
string.IsNullOrWhiteSpace(sender) ?
sender :
sender.TrimEnd(sender[^1]);
}
How to use
textBox1.Text = textBox1.Text.TrimLastCharacter();