Name

Trim Function

Syntax

Trim(string)
string

Use: Required

Data Type: String

Any string expression.

Return Value

A String.

Description

Returns a string in which any leading and trailing spaces in an original string are removed.

Rules at a Glance

If string is Null, the Trim function returns Null.

Programming Tips and Gotchas

Trim combines into a single function call what would otherwise be separate calls to the RTrim and LTrim functions.

VBA/VBScript Differences

VBA includes a Trim$ function that returns the a trimmed string rather than a trimmed string variant. Because VBScript does not support strong typing, the function is not implemented in VBScript.

Get VBScript in a Nutshell, 2nd 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.