Trim

Syntax:

  stringvar = Trim(stringvar)

Command Availability:

Available on all microcontrollers.

Explanation:

The Trim function trims the 7-bit ASCII space character (value 32) from text.

Trim removes all spaces from text except for single spaces between words. Use Trim on text you have received from another source that may have irregular spacing at the left or right-hand ends of the string.

Example:

    Dim TestData As String
    TestData = "   Hello   "

    TestData = TRIM(TestData)          ' <<< the TRIM instruction
    ' TestData now holds "Hello", with leading and trailing spaces removed

Key line: TRIM(TestData) — removes the spaces from both ends of TestData in a single call, equivalent to LTRIM followed by RTRIM.

See Also:

  • Ltrim — trimming only the left-hand side
  • Rtrim — trimming only the right-hand side