467,168 Members | 968 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,168 developers. It's quick & easy.

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
  • viewed: 6294
Share:
4 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Mad Scientist Jr | last post: by
4 posts views Thread by Bradley Plett | last post: by
10 posts views Thread by dba123 | last post: by
5 posts views Thread by jason@cyberpine.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.