C# String Trim()
Description
String Trim()
removes all leading and trailing white-space
characters from the current String object.
Syntax
String.Trim()
has the following syntax.
public string Trim()
Returns
String.Trim()
method returns The string that remains after all white-space characters are removed from
the start and end of the current string.
Example
The following example uses the String.Trim() method to remove any extra white space from strings.
/* w w w. ja v a 2s. c om*/
using System;
public class Example
{
public static void Main()
{
string firstName = " java2s.com ";
Console.WriteLine(firstName.Trim());
}
}
The code above generates the following result.