How to convert a string to a boolean?

I want to convert "true" to true.

I have seen the mono help at but when I try this I get an error ("Unkown Identifier")

I get the same error with Boolean.Parse.

Can anyone help?


All you have to do is comparing the string to “true”:

    bool mybool = someString == "true";

A lot people forget that the compare operators return a boolean value which you can use in an if-statement or assign it to a variable of type bool.

Some prefer to put some brackets like this:

    bool mybool = (someString == "true");

You can use “System.Convert.ToBoolean(someString)” as well, but keep in mind that it only works with the string “True” or “False” and will throw an exception if it contains anything else. My approach will return always false unless it’s “true”. Keep in mind that you can also check for multiple strings. In this case it’s best to wrap them in a method:

    public static bool ToBool(string aText)
       return aText == "true" || aText == "on" || aText == "yes";

if the value you get, always is "true", you can make an if like this

string valueYouGet="";
//by this line your variable, valueYouGet should be "true", by your own means
bool mybool = false;
if(valueYouGet == "true")
   mybool = true;

is not exactly a parser, but do the trick

hope this is the answer you are looking for

you simply should import the type System and call Convert.ToBoolean as:

import System;
function Start() {

and is exactly a parser