mhuss utils 1.1.5ws

com.mhuss.Util
Class Str

java.lang.Object
  extended by com.mhuss.Util.Str

public class Str
extends java.lang.Object

This class holds a potporri of static String functions not included in java.lang.String.


Constructor Summary
Str()
           
 
Method Summary
static boolean boolCheck(java.lang.String tf)
          Check for a string which represents boolean true.
static java.lang.String deSpace(java.lang.String s)
          Remove spaces, commas, dots and single quotes from a String.
static java.lang.String escape(java.lang.String in)
          Make a String URL-friendly by escaping all reserved chars.
static int extractInt(java.lang.String s)
          Extract the first digit substring from the passed in String and convert to an int.
static java.lang.String fmt(int i)
          Format a String representation of an integer using a default width of two (2).
static java.lang.String fmt(int i, char suffix)
          Format a String representation of an integer using a default width of two (2), and add the specified suffix.
static java.lang.String fmt(int i, int w)
          Format a String representation of an integer at the specified width.
static java.lang.String fmt(int i, int w, char suffix)
          Format a String representation of an integer at the specified width, and add the specified suffix.
static java.lang.String hex(char c)
          Convert a char to a "%hh" string.
static java.lang.String unescape(java.lang.String in)
          Make a URL-friendly "escaped" String human-friendly.
static char unhex(java.lang.String h)
          Convert a "%hh" String to a char.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Str

public Str()
Method Detail

extractInt

public static int extractInt(java.lang.String s)
Extract the first digit substring from the passed in String and convert to an int.

Parameters:
s - The String to search
Returns:
The converted digits or -1 if no digits were found

deSpace

public static java.lang.String deSpace(java.lang.String s)
Remove spaces, commas, dots and single quotes from a String.

This is usually called to help make text into a reasonably safe filename.

Parameters:
s - The String to filter
Returns:
The filtered String

hex

public static java.lang.String hex(char c)
Convert a char to a "%hh" string.

Parameters:
c - char to convert
Returns:
%hh representation of char.

unhex

public static char unhex(java.lang.String h)
Convert a "%hh" String to a char.

Parameters:
h - String %hh representation of char.
Returns:
char represented by %hh parameter

escape

public static java.lang.String escape(java.lang.String in)
Make a String URL-friendly by escaping all reserved chars.

A handy function lifted from ECMAScript. The characters which are "escaped" (i.e., converted to %hh form) include all those which are not alphanumeric AND not in the set @*-_./ Probably the most commonly seen are "%20", which represents the space (" ") character, and "%27", which represents the single quote ("'") character.

Example
Before: Foo's Funny Filename.html

After: Foo%27s%20Funny%20Filename.html

Parameters:
in - The String to escape
Returns:
The String with all reserved chars converted to "%hh" form.

unescape

public static java.lang.String unescape(java.lang.String in)
Make a URL-friendly "escaped" String human-friendly.

A handy function lifted from ECMAScript. The characters are are "unescaped" by converting all triglyphs of the form "%hh" to single characters. "+" signs are also converted to spaces.

Probably the most commonly seen are "%20", which represents the space (" ") character, and "%27", which represents the single quote ("'") character.

Example
Before: Foo%27s%20Funny%20Filename.html

After: Foo's Funny Filename.html

Parameters:
in - The String to unescape
Returns:
The String with all "%hh" triglyphs converted back to single characters.

boolCheck

public static boolean boolCheck(java.lang.String tf)
Check for a string which represents boolean true.

This function assumes a String which starts with 't', 'T', or '1' means true.

Parameters:
tf - The String to test
Returns:
true if the input has at least one character and evaluated as true, false otherwise . Note that a null input string returns false.

fmt

public static java.lang.String fmt(int i,
                                   int w)
Format a String representation of an integer at the specified width.

Note that this function will return an incorrect representation if the integer is wider than the specified width. For example:
fmt( 1, 3 ) will return "001"
fmt( 12, 3 ) will return "012"
fmt( 1234, 3 ) will return "234"

Parameters:
i - The integer to format
w - The format width
Returns:
A formatted String

fmt

public static java.lang.String fmt(int i,
                                   int w,
                                   char suffix)
Format a String representation of an integer at the specified width, and add the specified suffix.

Note that this will return an incorrect representation if the integer is wider than the specified width. For example:
fmt( 1, 3, ':' ) will return "001:"
fmt( 12, 3, ':' ) will return "012:"
fmt( 1234, 3, ':' ) will return "234:"

Parameters:
i - The integer to format
w - The format width
suffix - The character to append
Returns:
A formatted String

fmt

public static java.lang.String fmt(int i)
Format a String representation of an integer using a default width of two (2).

Note that this will return an incorrect representation if the integer is wider than two digits. For example:
fmt( 1 ) will return "01"
fmt( 12 ) will return "12"
fmt( 1234 ) will return "34"

Parameters:
i - The integer to format
Returns:
A formatted String

fmt

public static java.lang.String fmt(int i,
                                   char suffix)
Format a String representation of an integer using a default width of two (2), and add the specified suffix.

Note that this will return an incorrect representation if the integer is wider than the specified width. For example:
fmt( 1, ':' ) will return "01:"
fmt( 12, ':' ) will return "12:"
fmt( 1234, ':' ) will return "34:"

Parameters:
i - The integer to format
suffix - The character to append
Returns:
A formatted String

mhuss utils 1.1.5ws

bottom text