My question may sound weird but that's the scenario i'm at.
I need to parse an Excel formula (getting it from Office.Interop.Excel
) and get the parameters from the formula (# of parameter can vary)
There are multiple cases to consider.
E.g.:
1. myformula("param1", "param2")
2. myformula("param1", A2)
3. myformula("param1", , "param3")
4. myformula(A1, , "param3")
5. myformula("param1, has commas in it", "param2")
Is there a nicer way to parse this as opposed to having multiple if branches (especially considering when string array is mixed, i.e. some parameters have quotations and other parameters are reference parameters)?
Using string split(',')
doesn't seem to be too helpful as I can have commas in the parameter itself.
I've also tried
string[] paramArray = new string[]{(parameters)}
where parameters = "\"param1\", \"param2\"";
but that didn't seem to work either (it won't work at all if I have an empty parameter but that's another case).
My outcome should be some sort of an array (or list or any other collection) that would contain all of the parameters, and if a parameter didn't have quotation marks in it then I would need to evaluate it.
Any help would be appreciated.