Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6014975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:46:10+00:00 2026-05-23T02:46:10+00:00

C#: I have a string variable that looks like this: string a = (true

  • 0

C#: I have a string variable that looks like this:

 string a = "(true and true) or (true or false)";

This can be anything, it can get more complex, like:

 string b = "((true and false) or (true or false) and not (true and false)) and false";

All i know is that it is correct. Cannot happen that this expression cannot be “evaluated”.

Is there a way that I can somehow evaluate this? I would only like to know the outcome (result) of that string. This means I need “true” or “false” instead of this string.

I think I can make a parse method that does this, reducing the string step by step, until we got the final value, but I was wondering if there is a better approach.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T02:46:11+00:00Added an answer on May 23, 2026 at 2:46 am

    Something like this maybe?

    string previous = string.Empty;
    while (b != previous) 
    {
         previous = b;
         b = b.Replace("true and false", "false");
         b = b.Replace("true and true", "true");
         b = b.Replace("false and true", "false");
         b = b.Replace("false and false", "false");
         b = b.Replace("false or false", "false");
         b = b.Replace("true or false", "true");
         b = b.Replace("true or true", "true");
         b = b.Replace("false or true", "true");
         b = b.Replace("(false)", "false");
         b = b.Replace("(true)", "true");
         b = b.Replace("not false", "true");
         b = b.Replace("not true", "false");
     }
    

    Note that the specification allows ambigious formulations, such as these:

    "false and false or true"
    "false and true or true"
    

    Both of these expressions are “true” if the and is evaluted first, and “false” if the or is evaluated first. Therefore, requireing parenthesis at every level would be better. Requiring left-to-right evaluation is another option, but that makes the code a bit more complex.

    For those of you who may object to this style of solution for this style of problem, remember that some mathematicians believe that all of mathematics may be reduced to this sort of symbol manipulation. It is said that one of the main criticisms of Russell and Whitehead’s Principia Mathematica is that it embues the formulas with too much meaning.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a time string that looks like this: 5:34 pm . I want
I have string like this /c SomeText\MoreText Some Text\More Text\Lol SomeText I want to
I have a session variable that I set like this: <?php $token = md5(uniqid(rand(),
I have a dict of configuration variables that looks something like this: self.config =
I have one array that contains some settings that looks like basically like this:
I have an xml file that looks like this: <args> <sometag value=abc /> <anothertag
I have a xml that looks like this, <Parent> Running text with marked up
I have a string variable that represents the name of a custom class. Example:
When using CDT I would like to have std::string show up in the 'variable'
I have a variable of type Hashmap <String,Integer >. In this, the Integer value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.