Table of contents
TOC
折叠目录
展开目录

LTrim、RTrim 和 Trim 函数LTrim, RTrim, and Trim Functions

office 365 dev account|上次更新日期: 2018/3/13
|
2 参与人员

返回一个variant 类型的值字符串) 包含不带前导空格 ( LTrim ),指定字符串的副本尾随空格 ( RTrim ) 或 ( Trim ) 的前导和尾随空格。语法LTrim字符串RTrim字符串修剪字符串)必需的_字符串_参数是任何有效的字符串表达式。如果_字符串_中包含Null,则返回NullReturns a Variant ( String ) containing a copy of a specified string without leading spaces ( LTrim ), trailing spaces ( RTrim ), or both leading and trailing spaces ( Trim ). SyntaxLTrim ( string ) RTrim ( string ) Trim ( string ) The required stringargument is any validstring expression. If string containsNull, Null is returned.

示例Example

本示例使用LTrim函数去除前导空格,并使用RTrim函数删除字符串变量中的尾随空格。它使用Trim函数来去除这两种类型的空格。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.

Dim MyString, TrimString
MyString = "  <-Trim->  "    ' Initialize string.
TrimString = LTrim(MyString)    ' TrimString = "<-Trim->  ".
TrimString = RTrim(MyString)    ' TrimString = "  <-Trim->".
TrimString = LTrim(RTrim(MyString))    ' TrimString = "<-Trim->".
' Using the Trim function alone achieves the same result.
TrimString = Trim(MyString)    ' TrimString = "<-Trim->".

© 2018 Microsoft