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 4 6630
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
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 http://www.ramuseco.com
Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm
Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm
All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
"davebythes ea" <da**********@d iscussions.micr osoft.comwrote in message
news:6A******** *************** ***********@mic rosoft.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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mad Scientist Jr |
last post by:
Has anyone worked on code that that can parse evaluation expressions
(could be numbers or strings) like
( ( "dog" = "dog" ) or "foo" = "bar" ) and ("cow" = "bat" and "bye" =
"hi") or ("math" = "fun")
or
( ( 1 = 5 ) or ( 2 < 3 ) ) and (1 <= 6)
|
by: Bradley Plett |
last post by:
I have what should be a trivial problem. I am using XMLSerializer to
serialize an object. It serializes boolean values as "True" and
"False". I then want to use an XSLT on this XML, and I want to use
one of these booleans in a test. How do I convert one of these to a
boolean in a test?!? I know that I could compare it as a string to
"True" or "False", but that seems extremely crude to me. The
"boolean()" function (which, to me, seems...
|
by: Plamen Kouzov |
last post by:
I have a string, generated at runtime, which I want to convert to a
boolean.
The string can be something like:
"(true or false or true) andalso false"
"false orelse true"
, pretty much any string of booleans with the operators "and", "or",
"andalso", "orelse".
|
by: hazz |
last post by:
I get an InvalidCastException "Cast from string "6<5" to type 'Boolean is
not valid.
for
If (CInt(objBuyInfo.Budget) & " " & arrRuleList(i).operator & " "
& CInt(arrRuleList(i).LeadMemberValue)) Then
where arrRuleList(i).operator = ">"
|
by: dba123 |
last post by:
Why am I getting this error for Budget?
Error: An exception of type 'System.FormatException' occurred in
mscorlib.dll but was not handled in user code
Additional information: String was not recognized as a valid Boolean.
Public Sub UpdateCustomer_DashboardGraphs(ByVal sender As Object, ByVal
e As System.EventArgs)
| |
by: jason |
last post by:
Though this code appears to work, I suspect it could be streamline.
Total Noob Here.
public bool isit(string c1)
{
string color1 = "blue green red";
Regex re = new Regex("@"+c1, RegexOptions.IgnoreCase |
RegexOptions.Multiline);
if (re.Matches(color1).Count 0)
|
by: Simon Brooke |
last post by:
The DOM API has included public Node importNode(Node,boolean) as a method
of the Document interface for a long time. Does anything actually
implement it? Xerces 2 is giving me:
org.w3c.dom.DOMException: NOT_SUPPORTED_ERR: The implementation does not
support the requested type of object or operation.
at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown
Source)
at org.apache.xerces.dom.CoreDocumentImpl.importNode(Unknown
Source)
|
by: teddysnips |
last post by:
I have a notional Boolean value stored in the Registry. Actually it's
a REG_DWORD capable of taking values of either 0 or 1.
So, I need to populate a checkbox on a form dependent on this value.
1. I tried this:
chkLogToFile.Checked =
Boolean.Parse(LogFileKey.GetValue("LogToFile"));
|
by: smartic |
last post by:
I need to use this string "preg_match('$pattern','$value')" to return boolean value in if statment how can i do that i used eval function put it give me this error (Parse error: syntax error, unexpected $end in : eval()'d code on line 1)
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |