Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear sir


i have a string having like string str= (7+((8%2)(7%3))) how to solve this equation it may be any type like (7+8(10/2)*10) can any one plz tell me how to solve this string.
Posted
Updated 4-Jan-20 21:44pm

 
Share this answer
 
You are first going have to express your equations in a C# compatible format.

C# does not do implicit multiplication if two different expressions in parentheses are adjacent:

(7+((8%2)(7%3))) will not compile in C#: (7+((8%2)*(7%3))) will.

Transforming a string that does express implicit multiplication is, however, easy:
C#
string equationString = "(7+((8%2)(7%3)))";
string explicitMultiply = equationString.Replace(")(", ")*(");
But, if you had an expression of the form "5(10)," and expected that to multiply 5 x 10: that would require another type of fix.
 
Share this answer
 
Comments
rajbir singh thind 8-Oct-13 0:43am    
first the equation between brackets should solve and then the outer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900