How to remove last special character using C#?

How to remove last special character using C#?, someone asked me to explain?

remove first character from string c#

Remove last special character if last character is question mark. First we have to check the last character in given string is question mark or not. If last character is question mark then we remove the last character.

You can remove any last specific character if it exists at last position with the help of given example using c#. This function will retrurn text without special charcter ?. 

 public static string RemoveLastSpecialCharcter(string text)
        {
            var last_character = text[text.Length - 1];
            if (last_character == '?')
            {
                text = text.Remove(text.Length - 1);
            }
            return text;
       }

 

Post your comments / questions