•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C# section within the Software Development category of DaniWeb, a massive community of 375,214 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,273 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C# advertiser:
Views: 284 | Replies: 2
![]() |
•
•
•
•
IN C#:::
i have a string
string abc="40+40*4.2%+100"
now how can i get the result????
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.
c# Syntax (Toggle Plain Text)
class Program { static void Main(string[] args) { double abc = 40 + 40 * 4.2 % +100; Console.WriteLine(abc); Console.ReadLine(); } }
Answer is 108.
Regards,
PK
•
•
Join Date: Apr 2008
Location: Western New York
Posts: 10
Reputation:
Rep Power: 1
Solved Threads: 0
•
•
•
•
IN C#:::
i have a string
string abc="40+40*4.2%+100"
now how can i get the result????
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 :-)
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C# Marketplace
Similar Threads
- how do i compute for the time?? (Java)
- permutations of STRING Vs First n natural numbers (C++)
- Problem with string variable in void prnt function (C++)
- help on using StringTokenizer to read and compute multiple lines from text (Java)
- Function that returns void (C++)
Other Threads in the C# Forum
- Previous Thread: OLeDb Connection fail
- Next Thread: Static Cast


Linear Mode