org.af.commons.tools
Class StringTools

java.lang.Object
  extended by org.af.commons.tools.StringTools

public class StringTools
extends Object

This class provides various static methods for handling String objects.


Constructor Summary
StringTools()
           
 
Method Summary
static String arrayToString(Object[] strings)
          Converts an Object array Object[] obj to the String: "["+obj[0].toString()+", "+obj[1].toString()+","+ ... +", "+obj[obj.length].toString()+"]"
static int count(String s, String substring)
          Counts the occurrences of substring in String s.
static String getSubstringAfter(String s, String split, int i)
          Returns the substring from the i-th occurrence of split.
static String getSubstringBefore(String s, String split, int i)
          Returns the substring up to the i-th occurrence of split.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTools

public StringTools()
Method Detail

getSubstringBefore

public static String getSubstringBefore(String s,
                                        String split,
                                        int i)
Returns the substring up to the i-th occurrence of split. Example: getSubstringBefore("test.more.txt", ".", 2) returns "test.more". If split is not found i-times in s, the whole String s is returned.

Parameters:
split - Regular expression string to use for splitting.
Returns:
substring up to the i-th occurrence of split.

getSubstringAfter

public static String getSubstringAfter(String s,
                                       String split,
                                       int i)
Returns the substring from the i-th occurrence of split. Example: getSubstringBefore("test.more.txt", ".", 2) returns "txt". If split is not found i-times in s, the empty String "" is returned.

Parameters:
split - Regular expression string to use for splitting.
Returns:
substring from the the i-th occurrence of split.

count

public static int count(String s,
                        String substring)
Counts the occurrences of substring in String s.

Parameters:
s -
substring -
Returns:
Number of occurrences of substring in String s.

arrayToString

public static String arrayToString(Object[] strings)
Converts an Object array Object[] obj to the String: "["+obj[0].toString()+", "+obj[1].toString()+","+ ... +", "+obj[obj.length].toString()+"]"

Parameters:
strings -
Returns:
String that describes the content of the String array