|
-
July 16th, 2004, 09:46 AM
#1
Convert string to bool
Hi there,
how do I convert a string to a bool?
I get a string with "0" for false and "1" for true. At the moment I convert it twice, but I think that is not the best way.
Can someone give me a hint?
at the moment I do this:
Code:
Convert.ToBoolean(Convert.ToInt32(myString))
-
July 16th, 2004, 10:14 AM
#2
bool bvalue = (svalue == "1" ? true : false);
Regards,
Hal
up·grade (up'gräd'),
to take out old bugs
and put in new ones.
-
October 22nd, 2009, 01:28 PM
#3
Re: Convert string to bool
Your question was not at all clear. It depends on what you have in your 'string' value.
If you have 'true' or 'false' in your string value then all you need to do to convert the string value to a boolean is as follows:
bool booleanValue = Convert.ToBoolean(myString);
If you have '0' or '1' in your string value then
bool bvalue = (svalue == "1" ? true : false);
is what you need (noting that any value other than '1' will set bvalue to false).
-
October 25th, 2009, 10:39 PM
#4
Re: Convert string to bool
Slightly more concise...
Code:
String sValue = "0"; // or "1";
Boolean bValue = sValue.Equals("1");
Rob
-
Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|