VBA - array or collection literals?
»Chip Pearson« wrote:
Marcus,
Here's some code from my standard library that will do what you want, if I
understand your question properly:
You didn't, but I found a way in fact.
"ParamArray Delimiters() As Variant" is the trick...
then I can just specify the different delimiters in the function call.
Also...
Function MakeArray(ParamArray arr() As Variant) As Variant()
MakeArray = arr
End Function
looks like a useful utility function. Is there a conversion the other
way round, like "apply" in many languages? Think of it like this:
Dim args(3) As Variant
args(1) = "Hello World"
args(2) = 4
args(3) = 2
result = Apply(Mid, args)
' result is now "lo"
In other words, what I am looking for is a function with the property:
For each argument list ... and each function f,
f(...) = Apply(f, MakeArray(...))
hold.
From this, we can conclude:
Apply(MakeArray, somelist)
= Apply(MakeArray, MakeArray(items in somelist separated by comma))
= MakeArray(items in somelist separated by comma)
= somelist
so the other inversion does not need to be specified too.
Actually, what I originally wanted to have is a simpler regex-like way
to extract data out of strings, like:
Dim s As String
s = UnDelimit(htmlpage, "Number of items:<", "<td", "</td")(3)
Let htmlpage then be "...<thNumber if items:</th<td42</td...", then
UnDelimit would return the following list:
MakeArray("...<th", "/th", "42", "...")
Think of it as an equivalent to Perl's
my $s = ($htmlpage =~ m!^.*?Number of items:<.*?<td(.*?)</td.*$!);
Of course, the initial and final ^.*? or .*$ can be left out as they are
implicitly given in Perl REs. It's actually a simple function based on a
series of InStr.
|