VBA 字符串连接方法:& 符号和 Concat 方法
在 VBA 中,可以使用 ' & ' 符号将两个字符串连接起来。例如:
Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = 'Hello'
str2 = 'World'
str3 = str1 & ' ' & str2 ' 将 str1 和 str2 连接起来,并在它们之间添加一个空格
MsgBox str3 ' 输出 'Hello World'
除了使用 ' & ' 符号之外,还可以使用字符串的 Concat 方法来实现字符串的连接。例如:
Dim str1 As String
Dim str2 As String
Dim str3 As String
str1 = 'Hello'
str2 = 'World'
str3 = str1.Concat(' ', str2) ' 将 str1 和 str2 连接起来,并在它们之间添加一个空格
MsgBox str3 ' 输出 'Hello World'
原文地址: https://www.cveoy.top/t/topic/n45q 著作权归作者所有。请勿转载和采集!