![]() |
| ||
| how to compute a string in c#??? IN C#::: i have a string string abc="40+40*4.2%+100" now how can i get the result???? |
| ||
| Re: how to compute a string in c#??? Quote:
Hie Umang, As i know, you cant do manipulations in string type variables. You will have to use int, float or double type variable for it. class Program Answer is 108. Regards, PK:) |
| ||
| Re: how to compute a string in c#??? Quote:
I had this as a project in assembler class... it was fun You'll want to parse the string into smaller parts as you find the operators. Then put each one into a string that you can then convert to an int or double. Then where you find your operator perform the operation. But you have to perform them based upon priority... so for your current string you would parse it and find the operators you'll have strings "40", "+", "40", "*", "4.2", "*", ".01", "+", "100" you can have 2 temp vars(temp operator and temp double) and 2 stacks (operators and numbers) then as you pull them off the stack you check for priority of it versus the next operator then do the operation... store your cumulative answer and keep checking to see if there is more to do and do it Have fun with the code :-) |
| All times are GMT -4. The time now is 10:41 pm. |
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC