字符串函数String function

返回包含指定长度重复字符串的 Variant (String)。Returns a Variant (String) containing a repeating character string of the length specified.

语法Syntax

String(number, character)String(number, character)


String 函数语法有以下命名参数The String function syntax has these named arguments:

PartPart 说明Description
numbernumber 必需;LongRequired; Long. 所返回字符串的长度。Length of the returned string. 如果_number_包含null, 则返回nullIf number contains Null, Null is returned.
通配符character 必需;VariantRequired; Variant. 指定字符或字符串表达式字符代码,其第一个字符用于构建返回的字符串。Character code specifying the character or string expression whose first character is used to build the return string. 如果_字符_包含null, 则返回nullIf character contains Null, Null is returned.

备注Remarks

如果为大于255的_字符_指定一个数字, 则字符串将使用以下公式将该数字转换为有效的字符代码:字符 Mod 256。If you specify a number for character greater than 255, String converts the number to a valid character code by using this formula: character Mod 256.

示例Example

本示例使用 String 函数返回指定长度的重复字符串。This example uses the String function to return repeating character strings of the length specified.

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

另请参阅See also

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.