Remove Last Character from String in C#
To remove last char in a string in C# we can use the method String.Remove()
which has two overloaded forms: - Remove(Int32) - Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.
- Remove(Int32, Int32) - Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.
Example
using System;
public class Program
{
public static void Main()
{
string message = "hello users";
string messageFor1User = message.Remove(message.Length - 1, 1);
Console.WriteLine(messageFor1User);
}
}
Output
hello user