I'm trying to concatenate multiple strings and separate them by comma, and then subsequently to remove excess, leading and trailing commata.
For example, with an input of TEST("", "b", "c", "", "")
, I would like to get
b, c
However, my regex ,$| ,+|^,
does not really take repeated commas into account:
Function TEST(a, b, c, d, e)
res = a & ", " & b & ", " & c & ", " & d & ", " & e
Debug.Print (res)
Dim regex As Object, str, result As String
Set regex = CreateObject("VBScript.RegExp")
With regex
.Pattern = ",$| ,+|^,"
End With
Dim ReplacePattern As String
ReplacePattern = ""
res = regex.Replace(res, ReplacePattern)
TEST = res
End Function
How can I do this?