Boolean Parse string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?=

    Boolean Parse string

    Hi folks,

    Boolean.Parse(" true") returns true, but what if you need to parse something
    such as -

    Boolean.Parse(" (false && false) || (false || (true && true))");

    Does something exist in the .NET framework to Parse this kind of string to
    one final boolean result?

    Thanks for any tips,
    David
  • =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=

    #2
    RE: Boolean Parse string

    Dave,
    I suppose I must be reallyreallydum b, but why on earth would you ever need
    to do this? If its a legitimate business logic need, you could write a
    method that would be capable of parsing these expressions and returning bool.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    MetaFinder: http://www.blogmetafinder.com


    "davebythes ea" wrote:
    Hi folks,
    >
    Boolean.Parse(" true") returns true, but what if you need to parse something
    such as -
    >
    Boolean.Parse(" (false && false) || (false || (true && true))");
    >
    Does something exist in the .NET framework to Parse this kind of string to
    one final boolean result?
    >
    Thanks for any tips,
    David

    Comment

    • Bob Powell [MVP]

      #3
      Re: Boolean Parse string

      The Parse methods for the common value types are there to convert a simple
      string to the value. Evaluating expressions is not within its range of
      capabilities.

      You can write your own expression parser...

      --
      --
      Bob Powell [MVP]
      Visual C#, System.Drawing

      Ramuseco Limited .NET consulting


      Find great Windows Forms articles in Windows Forms Tips and Tricks


      Answer those GDI+ questions with the GDI+ FAQ


      All new articles provide code in C# and VB.NET.
      Subscribe to the RSS feeds provided and never miss a new article.


      "davebythes ea" <davebythesea@d iscussions.micr osoft.comwrote in message
      news:6ADE4446-96E7-4039-A830-DCC8FA869E46@mi crosoft.com...
      Hi folks,
      >
      Boolean.Parse(" true") returns true, but what if you need to parse
      something
      such as -
      >
      Boolean.Parse(" (false && false) || (false || (true && true))");
      >
      Does something exist in the .NET framework to Parse this kind of string to
      one final boolean result?
      >
      Thanks for any tips,
      David

      Comment

      • =?UTF-8?B?QXJuZSBWYWpow7hq?=

        #4
        Re: Boolean Parse string

        davebythesea wrote:
        Boolean.Parse(" true") returns true, but what if you need to parse something
        such as -
        >
        Boolean.Parse(" (false && false) || (false || (true && true))");
        >
        Does something exist in the .NET framework to Parse this kind of string to
        one final boolean result?
        That is not parsing. That is would be runtime expression evaluation.

        It can be done. But it will have some overhead and some security
        implications.

        Are you sure that you need this ?

        (I do have some code snippets if you really need it)

        Arne

        Comment

        • =?Utf-8?B?ZGF2ZWJ5dGhlc2Vh?=

          #5
          Re: Boolean Parse string

          Hi folks,

          Thanks for all your help. I'm going to have a think about all thats been
          said and work out my approach. Once (if) I make some progress I may come back
          and ask a couple more questions...

          Cheers,
          Dave

          "Arne Vajhøj" wrote:
          davebythesea wrote:
          Boolean.Parse(" true") returns true, but what if you need to parse something
          such as -

          Boolean.Parse(" (false && false) || (false || (true && true))");

          Does something exist in the .NET framework to Parse this kind of string to
          one final boolean result?
          >
          That is not parsing. That is would be runtime expression evaluation.
          >
          It can be done. But it will have some overhead and some security
          implications.
          >
          Are you sure that you need this ?
          >
          (I do have some code snippets if you really need it)
          >
          Arne
          >

          Comment

          Working...