473,508 Members | 2,142 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Feb 15 '08 #1
4 6618
Dave,
I suppose I must be reallyreallydumb, 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
"davebythesea" 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
Feb 15 '08 #2
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.
"davebythesea" <da**********@discussions.microsoft.comwrote in message
news:6A**********************************@microsof t.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
Feb 15 '08 #3
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
Feb 17 '08 #4
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
Feb 18 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
3580
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" =...
4
18699
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...
2
1753
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...
3
1994
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 & " " &...
10
16379
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...
5
2908
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,...
10
8770
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: ...
3
3970
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
1621
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,...
0
7225
marktang
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,...
0
7123
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...
0
7326
Oralloy
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,...
1
7046
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...
0
7498
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5627
agi2029
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,...
1
5053
isladogs
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...
0
3194
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...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.