How to check the last char of a string and see its a blank space How to check the last char of a string and see its a blank space asp.net asp.net

How to check the last char of a string and see its a blank space


Specific for one space character:

if(MyString.EndsWith(" "))    MyString = MyString.Substring(0, MyString.Length - 1);

or for any whitespace

MyString = MyString.TrimEnd();


string Original= "I am on Test ";string Temp = Original.Substring( Original.Length - 1 );Original = Original.Remove( Temp.Trim().Length > 0 ? 0 : Original.Length - 1);