Sign in with Microsoft
Sign in or create an account.
Hello,
Select a different account.
You have multiple accounts
Choose the account you want to sign in with.

會傳回 Variant (String) 包含指定字串的複本,其中不含前置空格 (LTrim) 、 RTrim) (結尾空格,或前置和結尾空格 (修剪) 。

語法

LTrim ( 字串 )

RTrim ( 字串 )

修剪 ( 字串 )

必要 字串引數 為任何有效的 字串運算式。 如果 string 包含 Null,就會傳回 Null

查詢範例

Expression

結果​​

SELECT LTrim (ProductDesc) AS 表達式1 FROM ProductSales;

傳回 「ProductDesc」 欄位中沒有前置空格的字串值,並顯示在 [表達式1] 欄中。

SELECT RTrim (ProductDesc) AS Expr1 FROM ProductSales;

傳回 「ProductDesc」 欄位中沒有結尾空格的字串值,並顯示在 [表達式1] 欄中。

SELECT LTrim (ProductDesc) AS NoTrailingSpace FROM ProductSales;

傳回 「ProductDesc」 字段中沒有前置空格的字串值,並顯示在 「NoTrailingSpace」 欄中。

SELECT RTrim (ProductDesc) AS NoLeadingSpace FROM ProductSales;

傳回 「ProductDesc」 欄位中沒有結尾空格的字串值,並顯示在 「NoLeadingSpaces」 欄中。

SELECT Trim (ProductDesc) AS Trimmed FROM ProductSales;

傳回 「ProductDesc」 欄位中的字串值,但不含前置和結尾空格,並顯示在「已修剪」欄中。

VBA 範例

附註: 下列範例示範如何在 Visual Basic for Applications (VBA) 模組中使用此函數。 如需使用 VBA 的詳細資訊,請在 [搜尋] 旁的下拉式清單中選取 [開發人員參考],並在 [搜尋] 方塊中輸入一個或多個字詞。

此範例使用 LTrim 函數來去除前置空格, 而 RTrim 函數則會從字串變數中去除結尾空格。 它使用 Trim 函數來去除這兩種類型的空格。

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->".

字串函數及其使用方法

Need more help?

Want more options?

探索訂閱權益、瀏覽訓練課程、瞭解如何保護您的裝置等等。

社群可協助您詢問並回答問題、提供意見反應,以及聆聽來自具有豐富知識的專家意見。

Was this information helpful?

How satisfied are you with the translation quality?
What affected your experience?
By pressing submit, your feedback will be used to improve Microsoft products and services. Your IT admin will be able to collect this data. Privacy Statement.

Thank you for your feedback!

×