I have a string say
\"Hello! world!\"
I want to do a trim or a remove to take out the ! off world but not off Hello.
Slightly modified version of @Damian Leszczyński - Vash that will make sure that only a specific character will be removed.
public static class StringExtensions
{
public static string TrimLastCharacter(this string str, char character)
{
if (string.IsNullOrEmpty(str) || str[str.Length - 1] != character)
{
return str;
}
return str.Substring(0, str.Length - 1);
}
}