fi.hut.tml.xsmiles.util
Class StringUtils

java.lang.Object
  extended byfi.hut.tml.xsmiles.util.StringUtils

public abstract class StringUtils
extends java.lang.Object

StringUtils.java Several utilities dealing with strings. Taken from freely available java tools at: http://industry.ebi.ac.uk/~senger/tools/

Version:
$Id: StringUtils.java 6355 2006-02-06 13:22:42Z honkkis $
Author:
Juha Muilu

Field Summary
static java.lang.String VERSION
          Version and date of the last update.
 
Constructor Summary
StringUtils()
           
 
Method Summary
static java.lang.String delete(java.lang.String string, java.lang.String delete)
          Delete all occurrences of substrings from a string.
static java.lang.String join(java.lang.String[] stringList)
          Make one string out of stringList by putting spaces between each element.
static java.lang.String join(java.lang.String[] stringList, java.lang.String delimiter)
          Opposite of split; concatenates STRINGLIST using DELIMITER as the separator.
static int numBeforeLocation(char CHAR, java.lang.String str, int loc)
          number of occurrences of character CHAR before location loc in string str.
static int[] positions(char CHAR, java.lang.String str)
          return list of positions of character CHAR inside string str.
static java.lang.String removePositions(java.lang.String str, int[] pos)
          Opposit string.
static java.lang.String removeWhites(java.lang.String str)
          removes all whitespace and 'unprintables characters' from String str, and returns new one.
static java.lang.String replace(java.lang.String string, java.lang.String from, java.lang.String to)
          In string S, replace all occurrence of FROM by TO and return this string.
static java.lang.String stripChar(char CHAR, java.lang.String str)
          remove occurrences of character CHAR from string STR.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VERSION

public static final java.lang.String VERSION
Version and date of the last update.

See Also:
Constant Field Values
Constructor Detail

StringUtils

public StringUtils()
Method Detail

stripChar

public static java.lang.String stripChar(char CHAR,
                                         java.lang.String str)
remove occurrences of character CHAR from string STR.

Parameters:
CHAR - The character to be removed.
str - The string from which to remove them
Returns:
string with CHARs removed

numBeforeLocation

public static int numBeforeLocation(char CHAR,
                                    java.lang.String str,
                                    int loc)
number of occurrences of character CHAR before location loc in string str.

Parameters:
CHAR - character whose occurrences should be counted
str - the string in which to do this
loc - the offset in str at which to start.
Returns:
number of occurrences.

positions

public static int[] positions(char CHAR,
                              java.lang.String str)
return list of positions of character CHAR inside string str.

Parameters:
CHAR - the character whose positions are sought
str - the string in which to find them
Returns:
a (possibly empty) list of integers that lists the positions at which CHAR was found.

removeWhites

public static java.lang.String removeWhites(java.lang.String str)
removes all whitespace and 'unprintables characters' from String str, and returns new one.

Parameters:
str - The string on which to operate
Returns:
a string that doesn't have the whitespace nor unprintables

join

public static java.lang.String join(java.lang.String[] stringList,
                                    java.lang.String delimiter)
Opposite of split; concatenates STRINGLIST using DELIMITER as the separator. The separator is only added between strings, so there will be no separator at the beginning or end.

Parameters:
stringList - The list of strings that will to be put together
delimiter - The string to put between the strings of stringList
Returns:
string that has DELIMITER put between each of the elements of stringList

join

public static java.lang.String join(java.lang.String[] stringList)
Make one string out of stringList by putting spaces between each element. Same as join(stringList, " ");

Parameters:
stringList - the list of strings that will be put together
Returns:
a string that has ' ' put between each of the elements of stringList.
See Also:
join(String[],String)

replace

public static java.lang.String replace(java.lang.String string,
                                       java.lang.String from,
                                       java.lang.String to)
In string S, replace all occurrence of FROM by TO and return this string. If string FROM is empty, this will be considered to match no single occurrence of it in the target string, hence no replacements will be made.

Parameters:
string - The string in which the replacements will be made
from - String that, when it occurs in string, will be replaced
to - The replacement of from in string
Returns:
A new string

delete

public static java.lang.String delete(java.lang.String string,
                                      java.lang.String delete)
Delete all occurrences of substrings from a string. Same as replace(string, from, "")

Parameters:
string - The string from which substrings will be deleted.
delete - The substrings that are to be deleted.
Returns:
new string.
See Also:
replace(String, String, String)

removePositions

public static java.lang.String removePositions(java.lang.String str,
                                               int[] pos)
Opposit string.

Parameters:
str - string
pos - positions of chars to be removed (must be ordered from lowest to highest and position can occur only once)
Returns:
new string from which the chars are removed


X-Smiles 1.2