LTrim - VBScript


Overview

The LTrim command in VB Script removes leading whitespace characters (spaces, tabs, carriage returns, line feeds) from a string. It is commonly used to clean up text input and ensure consistent string formatting.

Syntax

LTrim(string)

Parameters:

  • string: The input string to trim leading whitespace from.

Options/Flags

None

Examples

' Trim leading whitespace from a string
Dim str = "   Hello World"
str = LTrim(str)
' Result: "Hello World"

' Remove all whitespace characters from the beginning of a string
Dim str = "    "
str = LTrim(str)
' Result: ""

Common Issues

  • Ensure that the string provided is a valid string variable.
  • Note that the LTrim command only removes leading whitespace characters, not trailing or embedded whitespace.

Integration

The LTrim command can be combined with the RTrim and Trim commands to perform more comprehensive string trimming.

' Trim both leading and trailing whitespace
Dim str = "   Hello World    "
str = LTrim(str)
str = RTrim(str)
' Result: "Hello World"
  • RTrim: Removes trailing whitespace characters from a string.
  • Trim: Removes both leading and trailing whitespace characters from a string.