texsoft.java.util
Class XsStrUtil

java.lang.Object
  |
  +--texsoft.java.util.XsStrUtil

public abstract class XsStrUtil
extends java.lang.Object

This abstract class provides some usefull methods to manipulate String objects.


Constructor Summary
XsStrUtil()
           
 
Method Summary
static java.lang.String leftPad(java.lang.String s, char ch, int width)
          Returns s left padded with ch to width legnth.
static void main(java.lang.String[] args)
          Some test code.
static java.lang.String rightPad(java.lang.String s, char ch, int width)
          Returns s right padded with ch to width length.
static java.lang.String sequenceOf(char ch, int n)
          Returns a new String made by a sequence of n characters ch.
static java.lang.String[] split(java.lang.String s, char sep)
          Split s into substrings separed by the sep char.
static java.lang.String zeroPad(long value, int width)
          Convert value to String left padding with '0' to width length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XsStrUtil

public XsStrUtil()
Method Detail

zeroPad

public static java.lang.String zeroPad(long value,
                                       int width)
Convert value to String left padding with '0' to width length.

Parameters:
value - long to convert into string left pdded with '0'.
width - if the lenght of the string conversion of value is less than width, fill to left with '0' characters so that the resulting string will have width length.
Returns:
value converted to String and left padded with '0' characters up to width length.

split

public static java.lang.String[] split(java.lang.String s,
                                       char sep)
Split s into substrings separed by the sep char.

Returns the substrings into a String[]. Two consecutive sep chararcters will resolve into an zero-lenght substring. A leading or trailing sep character will generate a zero-lenght substring too.

Here are some examples:

 split("abc-12-xx", '-') -> { "abc", "12", "xx" }
 split("A/B//F", "/") -> { "A", "B", "", "F" }
 split("onlyone", ",") -> { "onlyone" }
 

Parameters:
s - the string to be split.
sep - the char that is used as split marker into the string.
Returns:
a String[] with the substrings.

sequenceOf

public static java.lang.String sequenceOf(char ch,
                                          int n)
Returns a new String made by a sequence of n characters ch.

Parameters:
ch - build the string with this char.
n - how many ch chars to put into the string.
Returns:
a String made by n ch characters.

leftPad

public static java.lang.String leftPad(java.lang.String s,
                                       char ch,
                                       int width)
Returns s left padded with ch to width legnth. If the s is longer than width it will be returned unchanged.

Parameters:
s - string to be left padded.
ch - use this char to left pad the string.
width - minimum width of the string; if the string's length is less that width, the it will be left padded with ch.
Returns:
the s string left padded with ch to width length.

rightPad

public static java.lang.String rightPad(java.lang.String s,
                                        char ch,
                                        int width)
Returns s right padded with ch to width length. If the s is longer than width it will be returned unchanged.

Parameters:
s - string to be right padded.
ch - use this char to right pad the string.
width - minimum width of the string; if the string's length is less that width, the it will be right padded with ch.
Returns:
the s string right padded with ch to width length.

main

public static void main(java.lang.String[] args)
Some test code.

Parameters:
args - command line arguments.