JEphem site
jephem API
Build classes

tig
Class Strings

java.lang.Object
  |
  +--tig.Strings
All Implemented Interfaces:
GeneralConstants

public abstract class Strings
extends java.lang.Object
implements GeneralConstants

Class containing utility static methods for String manipulation.


Field Summary
 
Fields inherited from interface tig.GeneralConstants
BLANK, FS, LS, NO_SPECIF, SPACE
 
Constructor Summary
Strings()
           
 
Method Summary
static java.lang.String doubleArrayToString(double[] doubleArray)
          Converts a double[] to a String.
static int findIndex(java.lang.String[] array, java.lang.String s)
          Finds the position of a String in an array (a String[]).
static java.lang.String intArrayToString(int[] intArray)
          Converts a int[] to a String.
static double parseDouble(java.lang.String s)
          Equivalent to java.lang.Double.parseDouble(String), but more permissive.
static java.lang.String replace(java.lang.String theString, java.lang.String s1, java.lang.String s2)
          All occurences of 's1' contained in 'theString' are replaced by s2.
static double[] stringToDoubleArray(java.lang.String str)
          Converts a String to an double[] ; in the String, the doubles must be separated by comas (',').
static int[] stringToIntArray(java.lang.String str)
          Converts a String to an int[] ; in the String, the integers must be separated by comas (',').
static java.lang.String[] stringToStringArray(java.lang.String s)
          Convenient method to call stringToStringArray(String, char), using a coma (',') as separator.
static java.lang.String[] stringToStringArray(java.lang.String s, char separator)
          Transforms a String in an array of Strings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Strings

public Strings()
Method Detail

findIndex

public static int findIndex(java.lang.String[] array,
                            java.lang.String s)
Finds the position of a String in an array (a String[]).

Parameters:
array - Arry of Strings where String 's' is searched.
s - String we want to locate in array
Returns:
The position of s in array, or GeneralConstants.NO_SPECIF if not found.

stringToStringArray

public static java.lang.String[] stringToStringArray(java.lang.String s)
Convenient method to call stringToStringArray(String, char), using a coma (',') as separator.


stringToStringArray

public static java.lang.String[] stringToStringArray(java.lang.String s,
                                                     char separator)
Transforms a String in an array of Strings.
Example : if s = "arg1, arg2,arg3 " and separator = ',', stringToStringArray returns :
arg1 arg2 arg3
Points to consider :
  • Leading and trailing spaces are removed (see arg2 and arg3).
  • Separators at the begining or at the end of s lead to creation of empty Strings in the resulting array.
  • The same thing happens if two separators are side by side :
    if s=",arg1,, arg2,arg3", stringToStringArray returns :
    (empty String) arg1 (empty String) arg2 arg3
  • Parameters:
    s - String to analyze.
    separator - Character used as separator to analyze s.
    Returns:
    An array of Strings resulting from the analysis.

    intArrayToString

    public static java.lang.String intArrayToString(int[] intArray)
    Converts a int[] to a String.
    Example : if 'intArray' contains 1, 4, -9 and 0 will be transfomed to "1, 4, -9, 0".


    stringToIntArray

    public static int[] stringToIntArray(java.lang.String str)
    Converts a String to an int[] ; in the String, the integers must be separated by comas (',').
    Example : if 'str' contains "1, 4, -9, 0", will be transfomed to new int[]{1, 4, -9, 0}.

    Throws:
    java.lang.NumberFormatException - If elements of 'str' can't be converted to integers.

    doubleArrayToString

    public static java.lang.String doubleArrayToString(double[] doubleArray)
    Converts a double[] to a String.
    Example : if 'doubleArray' contains 1.0, 0.0 and -9.5 will be transfomed to "1.0, 0.0, -9.5".


    stringToDoubleArray

    public static double[] stringToDoubleArray(java.lang.String str)
    Converts a String to an double[] ; in the String, the doubles must be separated by comas (',').
    Example : if 'str' contains "1, 4.02, -9.3, 0", will be transfomed to new double[]{1.0, 4.02, -9.3, 0.0}.

    Throws:
    java.lang.NumberFormatException - If elements of 'str' can't be converted to doubles.

    parseDouble

    public static double parseDouble(java.lang.String s)
    Equivalent to java.lang.Double.parseDouble(String), but more permissive. The string is converted to a double if the separator is a point or a coma.
    Ex : parseDouble("12.34") and parseDouble("12,34") will return the double 12.34.

    Parameters:
    s - The String that this method tries to convert into a double.
    Throws:
    java.lang.NumberFormatException - If 's' can't be parsed.

    replace

    public static java.lang.String replace(java.lang.String theString,
                                           java.lang.String s1,
                                           java.lang.String s2)
    All occurences of 's1' contained in 'theString' are replaced by s2. Equivalent to java.lang.String.replace(char, char), but with Strings.

    Parameters:
    theString - String to be modified.
    s1 - substring of 'theString' to be replaced by 's2'.
    s2 - String used to replace 's1' in 'theString'.
    Returns:
    'theString', modified as specified above.

    JEphem site
    jephem API
    Build classes