Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. String To Expression

String To Expression

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Elizma
    wrote on last edited by
    #1

    Hi Guys and Gals. I have a simple question, but for the life of me cant find an answer out there. I have a string that will contain an Expression: string x = "(2+3)+((7*2)-5)"; I need x to execute now as an expression in order to get the result of the expression. Eg. decimal y = (2+3)+((7*2)-5); [This is the value from the text string x] Result in y = 14 Your help will be greatly appreciated or your guidance to a possible workable solution. Kind Regards, Elizma

    OriginalGriffO W P 3 Replies Last reply
    0
    • E Elizma

      Hi Guys and Gals. I have a simple question, but for the life of me cant find an answer out there. I have a string that will contain an Expression: string x = "(2+3)+((7*2)-5)"; I need x to execute now as an expression in order to get the result of the expression. Eg. decimal y = (2+3)+((7*2)-5); [This is the value from the text string x] Result in y = 14 Your help will be greatly appreciated or your guidance to a possible workable solution. Kind Regards, Elizma

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Try this[^]

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      E 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        Try this[^]

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones "Rumour has it that if you play Microsoft CDs backwards you will hear Satanic messages.Worse still, is that if you play them forwards they will install Windows"

        E Offline
        E Offline
        Elizma
        wrote on last edited by
        #3

        Thanx for your help! I tried searching for it before I asked the question, but I guess my search criteria was wrong since the I put in "Convert String To Expression". I found something that works. E.g. string x = "(2+3)+((7*2)-5)"; DataTable dt = new DataTable(); object sumObject; sumObject = dt.Compute(x, ""); Elizma

        1 Reply Last reply
        0
        • E Elizma

          Hi Guys and Gals. I have a simple question, but for the life of me cant find an answer out there. I have a string that will contain an Expression: string x = "(2+3)+((7*2)-5)"; I need x to execute now as an expression in order to get the result of the expression. Eg. decimal y = (2+3)+((7*2)-5); [This is the value from the text string x] Result in y = 14 Your help will be greatly appreciated or your guidance to a possible workable solution. Kind Regards, Elizma

          W Offline
          W Offline
          wenjinxu
          wrote on last edited by
          #4

          use Reverse Polish Notation Expression can be analyzed Often used to calculate the string

          1 Reply Last reply
          0
          • E Elizma

            Hi Guys and Gals. I have a simple question, but for the life of me cant find an answer out there. I have a string that will contain an Expression: string x = "(2+3)+((7*2)-5)"; I need x to execute now as an expression in order to get the result of the expression. Eg. decimal y = (2+3)+((7*2)-5); [This is the value from the text string x] Result in y = 14 Your help will be greatly appreciated or your guidance to a possible workable solution. Kind Regards, Elizma

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            Reverse Polish Notation[^] and something to make use of it[^]. Or even CodeDom[^].

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups