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),包含指定長度的重複字元字串。

語法

字串 ( 數位、字元 )

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

引數

描述

number

必要。 長。 傳回字串的長度。 如果 number 包含 Null,就會傳回 Null

字元

必要。 變異。 字元代碼 指定用來建立傳回字串之字元或 字串運算式 字元。 如果 character 包含 Null,就會傳回 Null

註解

如果您為大於 255 的 字元 指定數位, String 會使用公式將數字轉換為有效的字元代碼:

字元 Mod 256

查詢範例

Expression

結果​​

SELECT ProductSales.ProductDesc, String (4, ProductDesc) AS testString FROM ProductSales;

傳回產品描述,在欄測試String 中重複產品描述的第一個字元 4 次。

VBA 範例

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

此範例使用 String 函數傳回指定長度的重複字元字串。

Dim MyString
MyString = String(5, "*") ' Returns "*****"
MyString = String(5, 42) ' Returns "*****"
MyString = String(10, "ABC") ' Returns "AAAAAAAAAA"

字串函數及其使用方法

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!

×