Wei Lin
Wei Lin

Reputation: 3811

how to convert excel formula to List or somestrongtype

There is a excel formula like :
=A2/B2*C2+D2

i expect to call somemethod like :

var formula = "=A2/B2*C2+D2";
var list = SomeMethod(formula);

and get List data like :

[0]:=
[1]:A2
[2]:/
[3]:B2
[4]:*
[5]:C2
[6]:+
[7]:D2

i have tried using regex for a while but i still have no idea.

Upvotes: 0

Views: 59

Answers (1)

Sushant Yelpale
Sushant Yelpale

Reputation: 889

Use Excel formula Parser for the case, check out here or here

EDIT

For Simple use case like only few operators +, -, / you could use following version,

string[] splits = Regex.Split("=A2/B2*C2+D2", @"(?<=[+-=*/])");

Upvotes: 2

Related Questions