C# Language String Manipulation Removing (Trimming) white-space from a string

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Example

The System.String.Trim method can be used to remove all leading and trailing white-space characters from a string:

string s = "     String with spaces at both ends      ";
s = s.Trim(); // s = "String with spaces at both ends"

In addition:

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";
s=str.Substring(26);  //s="retained"

s1 = s.Substring(0,5);  //s="A por"


Got any C# Language Question?