Variadic function parameters

How to dynamically provide a variable number of string prms to a variadic function.

Say I have a variadic function that accepts a variable number of strings. How can I call this function with dynamically generated parameters, say from a config file: stringA, stringB, stringC etc.

Can I ‘unwind’ a slice of strings?

Thanks in advance.
Jonathan

Given a function func f(s ...string) you can call it f(s1, s2, s3) etc.

If you have a slice of strings you can call it f(slice...), though you can not mix both calling conventions.

2 Likes

Thanks Norbert. The slice… method does it for me as I’m just reading strings from a config file.

Appreciated.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.