Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Strings.Trim(String) Method
Definition
- Namespace:
- Microsoft.VisualBasic
- Assembly:
- Microsoft.VisualBasic.Core.dll
- Assembly:
- Microsoft.VisualBasic.dll
- Source:
- Strings.vb
- Source:
- Strings.vb
- Source:
- Strings.vb
- Source:
- Strings.vb
- Source:
- Strings.vb
Important
Some information relates to prerelease product that may be substantially modified before itβs released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Returns a string containing a copy of a specified string with no leading spaces (LTrim), no trailing spaces (RTrim), or no leading or trailing spaces (Trim).
public:
static System::String ^ Trim(System::String ^ str);
public static string Trim(string? str);
public static string Trim(string str);
static member Trim : string -> string
Public Function Trim (str As String) As String
Parameters
- str
- String
Required. Any valid String expression.
Returns
A string containing a copy of a specified string with no leading spaces (LTrim), no trailing spaces (RTrim), or no leading or trailing spaces (Trim).
Examples
This example uses the LTrim function to strip leading spaces and the RTrim function to strip trailing spaces from a string variable. It uses the Trim function to strip both types of spaces.
' 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)
Remarks
The LTrim, RTrim, and Trim functions remove spaces from the ends of strings.
Applies to
See also
Feedback
Was this page helpful?
