com.croftsoft.core.text
Class ParseLib

java.lang.Object
  extended by com.croftsoft.core.text.ParseLib

public final class ParseLib
extends Object

A collection of static methods to parse primitive types.

Since:
1999-08-15
Version:
$Id: ParseLib.java,v 1.2 2006/10/01 07:36:51 croft Exp $
Author:
David Wallace Croft

Method Summary
static void main(String[] args)
           
static boolean parseBoolean(String s, boolean backup)
          Parses a boolean value from a String.
static double parseDouble(String s, double backup)
          Parses a double out of a String.
static int parseInt(String s, int backup)
          Returns backup if s is null or a NumberFormatException occurs.
static long parseLong(String s, long backup)
          Returns backup if s is null or a NumberFormatException occurs.
static String stripNonNumbers(String s)
          Strips non-number characters out of the String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

main

public static void main(String[] args)

parseBoolean

public static boolean parseBoolean(String s,
                                   boolean backup)
Parses a boolean value from a String.

All leading and trailing whitespace is trimmed and all characters are converted to lower case before the comparison.

Parameters:
backup - Default value to be returned is s is null or cannot be parsed.
Returns:
Returns false if s is "0", "f", "false", "n", "no" , or "off". Returns true if s is "1", "t", "true" , "y", "yes", or "on" . Otherwise returns backup value.

parseDouble

public static double parseDouble(String s,
                                 double backup)
Parses a double out of a String.

Parameters:
backup - Default value returned if unable to parse the String.

parseInt

public static int parseInt(String s,
                           int backup)
Returns backup if s is null or a NumberFormatException occurs.


parseLong

public static long parseLong(String s,
                             long backup)
Returns backup if s is null or a NumberFormatException occurs.


stripNonNumbers

public static String stripNonNumbers(String s)
Strips non-number characters out of the String.

Example: "$1,999.99 or best offer" ==> "1999.99"


CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)