Removing (Trimming) white-space from a string C# with Example
The System.String.Trim method can be used to remove all leading and trailing white-space characters from a
string s = " String with spaces at both ends ";
s = s.Trim(); // s = "String with spaces at both ends"
To remove white-space only from the beginning of a string use: System.String.TrimStart
To remove white-space only from the end of a string use: System.String.TrimEnd
Substring to extract part of a string.
The System.String.Substring method can be used to extract a portion of the string.
string s ="A portion of word that is retained";
s1 = s.Substring(0,5); //s="A por"