返回一个 Variant (String) 值,其中包含指定长度的重复字符串。
语法
字符串 ( 数字,字符)
String函数语法具有以下参数:
参数 | 说明 |
---|---|
number |
必需。 长。 返回的字符串的长度。 如果number包含 Null,则返回 Null。 |
字符 |
必需。 变体。 字符代码 指定第 字符串表达式 字符用于生成返回字符串的字符或字符串。 如果字符包含 Null,则返回 Null。 |
备注
如果为大于 255 的字符指定数字,字符串会使用公式将数字转换为有效的字符代码:
character Mod 256
查询示例
表达式 | 结果 |
---|---|
SELECT ProductSales.ProductDesc,字符串 (4,ProductDesc) AS testString FROM ProductSales; |
返回产品说明,在 testString 列中重复产品说明的第一个字符 4 次。 |
VBA 示例
注意: 以下示例演示了在 VBA Visual Basic for Applications (模块) 函数。 有关使用 VBA 的信息,请在"搜索"旁边的下拉列表中选择"开发人员参考",在搜索框中输入一个或多个术语。
此示例使用 String 函数返回指定长度的重复字符串。
Dim MyString
MyString = String(5, "*") ' Returns "*****"
MyString = String(5, 42) ' Returns "*****"
MyString = String(10, "ABC") ' Returns "AAAAAAAAAA"