org.apache.avalon.excalibur.util
Class StringUtil

java.lang.Object
  |
  +--org.apache.avalon.excalibur.util.StringUtil

public final class StringUtil
extends java.lang.Object

A set of utility operations that work on or create strings.

Version:
CVS $Revision: 1.12 $ $Date: 2001/12/31 21:36:50 $
Author:
Peter Donald

Field Summary
static java.lang.String LINE_SEPARATOR
          the line separator for this OS
 
Method Summary
static void appendWhiteSpace(java.lang.StringBuffer sb, int length)
          Append a certain number of whitespace characters to a StringBuffer.
static java.lang.String concat(java.lang.String[] list)
          Convenience utility to concatenate an array of strings together.
static java.lang.String concat(java.lang.String first, java.lang.String second, java.lang.String third)
          Convenience utility to concatenate three strings together.
static java.lang.String format(int minSize, int maxSize, boolean rightJustify, java.lang.String string)
          Utility to format a string given a set of constraints.
static void format(java.lang.StringBuffer sb, int minSize, int maxSize, boolean rightJustify, java.lang.String string)
          Utility to format a string given a set of constraints.
static java.lang.String hexDisplay(byte[] data, int length)
          Display bytes in hex format.
static java.lang.String join(java.lang.String[] strings, java.lang.String separator)
          Joins the string array using specified separator.
static java.lang.String replaceSubString(java.lang.String original, java.lang.String oldString, java.lang.String newString)
          Replace substrings of one string with another string and return altered string.
static java.lang.String[] split(java.lang.String string, java.lang.String onToken)
          Splits the string on every token into an array of strings.
static java.lang.String truncate(java.lang.String string, int length)
          Truncate a string to maximum length;
static java.lang.String truncateNicely(java.lang.String string, int length)
          Truncate a string in a nice manner.
static java.lang.String wordWrap(java.lang.String string, int column, boolean force)
          Wordwrap string to specified column.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

public static final java.lang.String LINE_SEPARATOR
the line separator for this OS
Method Detail

concat

public static final java.lang.String concat(java.lang.String first,
                                            java.lang.String second,
                                            java.lang.String third)
Convenience utility to concatenate three strings together.

concat

public static final java.lang.String concat(java.lang.String[] list)
Convenience utility to concatenate an array of strings together.

replaceSubString

public static final java.lang.String replaceSubString(java.lang.String original,
                                                      java.lang.String oldString,
                                                      java.lang.String newString)
Replace substrings of one string with another string and return altered string.
Parameters:
original - input string
oldString - the substring section to replace
newString - the new substring replacing old substring section
Returns:
converted string

hexDisplay

public static final java.lang.String hexDisplay(byte[] data,
                                                int length)
Display bytes in hex format.

The display puts hex display on left and then writes out textual representation on right. The text replaces any non-printing character with a '.'

Note that this code was based on work done by Barry Peterson on the Q2Java project

Parameters:
data - the bytes to display
length - the number of bytes to display per line
Returns:
The display string

truncate

public static final java.lang.String truncate(java.lang.String string,
                                              int length)
Truncate a string to maximum length;
Parameters:
string - the string
length - the length
Returns:
a truncated string or original string if it is short enough

truncateNicely

public static final java.lang.String truncateNicely(java.lang.String string,
                                                    int length)
Truncate a string in a nice manner. The method will attempt to truncate the string on whitespace and append "..." to the end.

wordWrap

public static final java.lang.String wordWrap(java.lang.String string,
                                              int column,
                                              boolean force)
Wordwrap string to specified column. if force is true then words that exceed column length will be cut otherwise each word will exist on a line by itself.
Parameters:
string - string to word-wrap
column - the column at which to wrap
force - true if string should be force split at column
Returns:
The word-wrapped string

split

public static final java.lang.String[] split(java.lang.String string,
                                             java.lang.String onToken)
Splits the string on every token into an array of strings.
Parameters:
string - the string
onToken - the token
Returns:
the resultant array

join

public static final java.lang.String join(java.lang.String[] strings,
                                          java.lang.String separator)
Joins the string array using specified separator.
Parameters:
strings - the array of strings to join
separator - the separator to use when joining
Returns:
the joined string

format

public static final java.lang.String format(int minSize,
                                            int maxSize,
                                            boolean rightJustify,
                                            java.lang.String string)
Utility to format a string given a set of constraints. TODO: Think of a better name than format!!!! ;)
Parameters:
minSize - the minimum size of output (0 to ignore)
maxSize - the maximum size of output (0 to ignore)
rightJustify - true if the string is to be right justified in it's box.
string - the input string

format

public static final void format(java.lang.StringBuffer sb,
                                int minSize,
                                int maxSize,
                                boolean rightJustify,
                                java.lang.String string)
Utility to format a string given a set of constraints. TODO: Think of a better name than format!!!! ;) Note this was thieved from the logkit project.
Parameters:
sb - the StringBuffer
minSize - the minimum size of output (0 to ignore)
maxSize - the maximum size of output (0 to ignore)
rightJustify - true if the string is to be right justified in it's box.
string - the input string

appendWhiteSpace

public static final void appendWhiteSpace(java.lang.StringBuffer sb,
                                          int length)
Append a certain number of whitespace characters to a StringBuffer.
Parameters:
sb - the StringBuffer
length - the number of spaces to append


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.