public class

StringUtils

extends Object
java.lang.Object
   ↳ chan.util.StringUtils

Class Overview

Provides some utilities to work with strings.

Summary

Nested Classes
interface StringUtils.ReplacementCallback

Replacement callback for replaceAll methods. 

Public Methods
static String clearHtml(String string)

Removes all HTML tags and transforms mnemonics.

static String emptyIfNull(CharSequence string)

Returns string.toString() if string is not null, otherwise returns empty string.

static boolean equals(String first, String second)

Returns whether strings are equals.

static boolean isEmpty(CharSequence string)

Returns whether string is null or empty.

static boolean isEmptyOrWhitespace(CharSequence string)

Returns whether string is null, empty or contains only whitespaces.

static String linkify(String string)

Append HTML links to text.

static int nearestIndexOf(String string, int start, char... what)

Returns the next index of the nearest of given what char array in string, or -1.

static int nearestIndexOf(String string, int start, String... what)

Returns the next index of the nearest of given what string array in string, or -1.

static String nullIfEmpty(String string)

Returns null if string is empty, otherwise returns string.

static String replaceAll(String string, String regularExpression, StringUtils.ReplacementCallback replacementCallback)

Replaces all matches for regularExpression within given string with the replacement provided by replacementCallback.

static String replaceAll(String string, Pattern pattern, StringUtils.ReplacementCallback replacementCallback)

Replaces all matches for compiled pattern within given string with the replacement provided by replacementCallback.

static String unescapeHtml(String string)

Removes all HTML tags and transforms mnemonics.

[Expand]
Inherited Methods
From class java.lang.Object

Public Methods

public static String clearHtml (String string)

Removes all HTML tags and transforms mnemonics. This method will handle spaces and line breaks.

Parameters
string String: Source string.
Returns
String Cleared source string.

public static String emptyIfNull (CharSequence string)

Returns string.toString() if string is not null, otherwise returns empty string.

Parameters
string CharSequence: String instance.
Returns
String Not null string.

public static boolean equals (String first, String second)

Returns whether strings are equals. May handle null values.

Parameters
first String: String instance.
second String: String instance.
Returns
boolean True if strings are equals.

public static boolean isEmpty (CharSequence string)

Returns whether string is null or empty.

Parameters
string CharSequence: String instance.
Returns
boolean True if string is empty.

public static boolean isEmptyOrWhitespace (CharSequence string)

Returns whether string is null, empty or contains only whitespaces.

Parameters
string CharSequence: String instance.
Returns
boolean True if string is empty or whitespace.

public static String linkify (String string)

Append HTML links to text.

Parameters
string String: Text to append links.
Returns
String Text with links.

public static int nearestIndexOf (String string, int start, char... what)

Returns the next index of the nearest of given what char array in string, or -1.

Parameters
string String: Where to search.
start int: Start offset.
what char: Char array to search.
Returns
int True if strings are equals.

public static int nearestIndexOf (String string, int start, String... what)

Returns the next index of the nearest of given what string array in string, or -1.

Parameters
string String: Where to search.
start int: Start offset.
what String: String array to search.
Returns
int True if strings are equals.

public static String nullIfEmpty (String string)

Returns null if string is empty, otherwise returns string.

Parameters
string String: String instance.
Returns
String Null string if s is empty.

public static String replaceAll (String string, String regularExpression, StringUtils.ReplacementCallback replacementCallback)

Replaces all matches for regularExpression within given string with the replacement provided by replacementCallback.

If the same regular expression is to be used for multiple operations, it may be more efficient to use replaceAll(String, Pattern, ReplacementCallback) method with compiled Pattern.

Parameters
string String: Source string.
regularExpression String: Regular expression string.
replacementCallback StringUtils.ReplacementCallback: StringUtils.ReplacementCallback instance.
Returns
String Resulting string.

public static String replaceAll (String string, Pattern pattern, StringUtils.ReplacementCallback replacementCallback)

Replaces all matches for compiled pattern within given string with the replacement provided by replacementCallback.

Parameters
string String: Source string.
pattern Pattern: Compiled regular expression.
replacementCallback StringUtils.ReplacementCallback: StringUtils.ReplacementCallback instance.
Returns
String Resulting string.

public static String unescapeHtml (String string)

Removes all HTML tags and transforms mnemonics. This method will not handle spaces and line breaks.

Parameters
string String: Source string.
Returns
String Escaped source string.