System.String.Trim Method

Removes all leading and trailing white-space characters from the current string object.

Syntax

public string Trim ()

Returns

The string that remains after all white-space characters are removed from the start and end of the current string.

Remarks

The string.Trim method removes from the current string all leading and trailing white-space characters. Each leading and trailing trim operation stops when a non-white-space character is encountered. For example, if the current string is " abc xyz ", the string.Trim method returns "abc xyz".

Note:

This method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing white space characters found in the current instance are removed.

If the current string equals string.Empty or all the characters in the current instance consist of white-space characters, the method returns string.Empty.

White-space characters are defined by the Unicode standard. The string.Trim method removes any leading and trailing characters that produce a return value of true when they are passed to the char.IsWhiteSpace(char) method.

Requirements

Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0