Convert a numeric expression which is stored as string into integer in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • priravi
    New Member
    • May 2007
    • 11

    Convert a numeric expression which is stored as string into integer in C#

    Hi,

    I'm having a numeric expression say

    "((2*3)-(3*4+5))" returned from a method as a string value... now i have to evaluate the expression and store it in an integer vaariable.

    Convert.toint or int.parse is not working and since i'm new to .net development i have no idea of how else to convert this.Please do help me regarding this
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    you will need to parse the string into your own set of grammer and perform the mathmatical operations yourself.

    Comment

    • priravi
      New Member
      • May 2007
      • 11

      #3
      Thanks..i guess there is no other simpler way to do thi right?

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        Not unless you can find a way to import a function from some other language that does it?

        Comment

        • coolsti
          Contributor
          • Mar 2008
          • 310

          #5
          Interesting. I see I have been working too long with interpretive scripting languages (like Perl and PHP). Its easy to forget that something like an "eval" function doesn't exist in a compiled software language.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by coolsti
            Interesting. I see I have been working too long with interpretive scripting languages (like Perl and PHP). Its easy to forget that something like an "eval" function doesn't exist in a compiled software language.
            If you do decide to go all the way with this then check out Jos' compiler series in the Java howTos section.

            Comment

            • coolsti
              Contributor
              • Mar 2008
              • 310

              #7
              Originally posted by r035198x
              If you do decide to go all the way with this then check out Jos' compiler series in the Java howTos section.
              Nice link to lots of good info! Thanks! No, I am coming from compiled languages, so I am not a newby here (Fortran submitted as batch jobs using punch cards back in 1972 was my first, what a pain!) but it is easy to get used to some of what interpreted languages offer :):):)

              Comment

              Working...