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 forStringmanipulation.
-
-
Constructor Summary
Constructors Constructor and Description Strings()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.StringdoubleArrayToString(double[] doubleArray)Converts adouble[]to a String.static intfindIndex(java.lang.String[] array, java.lang.String s)Finds the position of aStringin an array (aString[]).static java.lang.StringintArrayToString(int[] intArray)Converts aint[]to a String.static doubleparseDouble(java.lang.String s)Equivalent tojava.lang.Double.parseDouble(String), but more permissive.static java.lang.Stringreplace(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 andouble[]; in theString, the doubles must be separated by comas (',').static int[]stringToIntArray(java.lang.String str)Converts a String to anint[]; in theString, the integers must be separated by comas (',').static java.lang.String[]stringToStringArray(java.lang.String s)Convenient method to callstringToStringArray(String, char), using a coma (',') as separator.static java.lang.String[]stringToStringArray(java.lang.String s, char separator)Transforms aStringin an array ofStrings.
-
-
-
Method Detail
-
findIndex
public static int findIndex(java.lang.String[] array, java.lang.String s)Finds the position of aStringin an array (aString[]).- Parameters:
array- Arry of Strings where String 's' is searched.s- String we want to locate inarray- Returns:
- The position of
sinarray, orGeneralConstants.NO_SPECIFif not found.
-
stringToStringArray
public static java.lang.String[] stringToStringArray(java.lang.String s)
Convenient method to callstringToStringArray(String, char), using a coma (',') as separator.
-
stringToStringArray
public static java.lang.String[] stringToStringArray(java.lang.String s, char separator)Transforms aStringin an array ofStrings.
Example : ifs = "arg1, arg2,arg3 "andseparator = ',',stringToStringArrayreturns :
Points to consider :arg1 arg2 arg3 - Leading and trailing spaces are removed (see
arg2andarg3).- Separators at the begining or at the end of
slead to creation of empty Strings in the resulting array.- The same thing happens if two separators are side by side :
ifs=",arg1,, arg2,arg3",stringToStringArrayreturns :(empty String) arg1 (empty String) arg2 arg3 - Parameters:
s- String to analyze.separator- Character used as separator to analyzes.- Returns:
- An array of Strings resulting from the analysis.
- Leading and trailing spaces are removed (see
-
intArrayToString
public static java.lang.String intArrayToString(int[] intArray)
Converts aint[]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 anint[]; in theString, the integers must be separated by comas (',').
Example : if 'str' contains "1, 4, -9, 0", will be transfomed tonew 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 adouble[]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 andouble[]; in theString, the doubles must be separated by comas (',').
Example : if 'str' contains "1, 4.02, -9.3, 0", will be transfomed tonew 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 tojava.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")andparseDouble("12,34")will return the double12.34.- Parameters:
s- The String that this method tries to convert into adouble.- 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 tojava.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.
-
-
DMelt 3.0 © DataMelt by jWork.ORG