Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
M-R Functions
 Trim, LTrim, and RTrim Functions
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Basic Language Reference
Trim, LTrim, and RTrim Functions

Returns a string that contains a copy of a specified string without leading spaces (LTrim), without trailing spaces (RTrim), or without leading or trailing spaces (Trim).

Public Shared Function LTrim(ByVal str As String) As String
Public Shared Function RTrim(ByVal str As String) As String
Public Shared Function Trim(ByVal str As String) As String
str

Required. Any valid String expression. If str equals Nothing, the function returns an empty string.

The LTrim, RTrim, and Trim functions remove spaces from the ends of strings. To remove other forms of white space, such as tab characters, use the String..::.Trim method.

This example uses the LTrim function to remove leading spaces and the RTrim function to remove trailing spaces from a string variable. It uses the Trim function to remove both types of spaces.

Visual Basic
' Initializes string.
Dim TestString As String = "  <-Trim->  "
Dim TrimString As String
' Returns "<-Trim->  ".
TrimString = LTrim(TestString)
' Returns "  <-Trim->".
TrimString = RTrim(TestString)
' Returns "<-Trim->".
TrimString = LTrim(RTrim(TestString))
' Using the Trim function alone achieves the same result.
' Returns "<-Trim->".
TrimString = Trim(TestString)

Namespace: Microsoft.VisualBasic

Module: Strings

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker