String 函数

应用对象
Microsoft 365 专属 Access Access 2024 Access 2021 Access 2019 Access 2016

返回一个 Variant (String) 值,其中包含指定长度的重复字符串。

语法

字符串 (数字、字符)

String 函数语法具有以下参数:

参数 说明
数量 必需。 长。 返回字符串的长度。 如果 number 包含 Null,则返回 Null
字符 必需。 变异。 字符代码,指定其第一个字符用于生成返回字符串的字符或字符串表达式。 如果 字符 包含 Null,则返回 Null

备注

如果为大于 255 的 字符 指定数字, 则 String 将使用公式将该数字转换为有效的字符代码:

characterMod 256

查询示例

Expression 结果
SELECT ProductSales.ProductDesc, String (4,ProductDesc) AS testString FROM ProductSales; 返回产品说明,在 testString 列中重复第一个字符 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"

字符串函数以及如何使用它们