Home  |  Contact         

Zrinity is the leader in enterprise-class email marketing management solutions and content management solutions for marketing professionals and developers worldwide.
Products Services Solutions Support Resources Partners Company
Java, PHP, CF Code Samples

Converts strings like true, false, yes, no, 1, and 0 to a java boolean variable.
public class Utility 
{

 public static final boolean stringToBoolean(String str) 
 {
        if (str.equals("0")) {
            return false;
        }
        str = str.toLowerCase();
        if (str.equals("false")) {
            return false;
        }
        if (str.equals("no")) {
            return false;
        }
        //if it's non false, it's true by definition
        return true;
 }

 /* now lets test it */
 public static void main(String args[])
 {
        if (args.length > 0) {
            if (Utility.stringToBoolean(args[0])) {
                System.out.println(args[0] + " is TRUE");
            }
            else {
                System.out.println(args[0] + " is FALSE");
            }  
        }
        else {
            System.out.println("Run the program with a bool to test");
        }
 }
}


More Code Samples



  
home products services partners company support contact
Copyright 2006 © Zrinity Inc. All rights reserved.     View our privacy policy         September 9, 2010