Trim Method

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public string Trim()

Return Value

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

The 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 Trim method returns "abc   xyz".

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

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

Show: