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),包含某字串從最右側字元開始之指定數目的字元。

語法

右 ( 字串、長度 )

Right 函數語法具有下列自變數:

引數

描述

string

必要。 字串運算式 傳回最右邊的字元。 如果 string 包含 Null,就會傳回 Null

length

必要。 Variant (Long) 。 指出要傳回多少字元的數值表達式。 如果為 0,則會傳回零長度字串 (“) 。 如果大於或等於 字串中的字元數,則會傳回整個字串。

註解

若要判斷 string 中的字元數,請使用 Len 函數。

附註:  使用 RightB 函數搭配字串中包含的位元組數據。 length 不會指定要傳回的字元數,而是指定位元組數。

查詢範例

Expression

結果​​

SELECT Right (ProductID,3) AS FromRight FROM ProductSales;

從 FromRight 資料行 「ProductSales」 資料表 「ProductSales」 的 [ProductID] 字段值右側傳回 「3」字元。

VBA 範例

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

此範例使用 Right 函數從字串右側傳回指定的字元數。

Dim AnyString, MyStr
AnyString = "Hello World" ' Define string.
MyStr = Right(AnyString, 1) ' Returns "d".
MyStr = Right(AnyString, 6) ' Returns " World".
MyStr = Right(AnyString, 20) ' Returns "Hello World".

字串函數及其使用方法

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!

×