Name

Trim Function

Class

Microsoft.VisualBasic.Strings

Syntax

Trim(str)
str (required; String)

Any string expression

Return Value

String

Description

Removes both leading and trailing spaces from a given string

Rules at a Glance

If string is Nothing, the Trim function returns Nothing.

Programming Tips and Gotchas

Trim is equivalent to calling both the RTrim and LTrim functions.

VB.NET/VB 6 Differences

In VB 6, the function’s single named argument is string. In VB.NET, its single named argument is str.

Get VB.NET Language in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.