c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

How to remove last special character using C#?

| | CSharp

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;
       }