我正在尝试将数组值列表转换为逗号分隔的字符串,并带有单引号。
我的数组名称是:
info.arr_fonts(
(0)times
(1)verdana
(2)arial
(3)tahoma
(4)helvetica
) - values are dynamic, can be +/-.
enter code here
我想把它们写成一个字符串变量,如:
"times, verdana, arial, tahoma, helvetica"
有人能告诉我这是怎么做到的吗?我尝试过一些简单的事情:
Dim strFonts As String
strFonts = Join(info.FontArray, ",")
但是这并没有在每个单词周围添加单引号。
更新
Dim arrFontNames As Variant
Dim strFonts As String
Dim lCtr As Long
arrFontNames = Array("Doremi", "Times-Roman", "Helvetica", "Jivetalk", "Jive")
strFonts = Join(arrFontNames, ",")
strFonts的内容:
"Doremi,Times-Roman,Helvetica,Jivetalk,Jive"
我需要将strFonts作为参数传递给存储过程。存储过程需要接收它:
'Doremi,Times-Roman,Helvetica,Jivetalk,Jive'
一旦执行存储过程,VBA的双引号会转换为单引号,还是我还需要进行一些字符串操作?
答案 0 :(得分:1)
按循环添加引号。
Sub test()
Dim lCtr As Long
For lCtr = LBound(info.FontArray) To UBound(info.FontArray)
info.FontArray(lCtr) = "'" & info.FontArray(lCtr) & "'"
Next
strFonts = Join(info.FontArray, ",")
End Sub
根据您对该问题的编辑。对于存储过程中的单个参数,您需要做的就是
strFonts = "'" & Join(info.FontArray, ",") & "'"