com.jstatcom.util
Class UString
- java.lang.Object
-
- com.jstatcom.util.UString
-
public final class UString extends java.lang.ObjectA collection of static methods that are related to strings and formatting.
-
-
Field Summary
Fields Modifier and Type Field and Description static java.lang.StringNAN_STRINGstatic java.lang.StringNAN_STRING_ALTstatic java.lang.StringNEGINF_STRINGstatic java.lang.StringPOSINF_STRINGstatic java.lang.StringSIGPOSINF_STRING
-
Constructor Summary
Constructors Constructor and Description UString()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method and Description static java.lang.StringcapitalizeFirst(java.lang.String s)Resturns string with first characted capitalized, rest lowercase.static java.lang.StringformatNumber(double number, java.text.NumberFormat format, int precision)Formatsnumberwithformatifformat != null.static java.lang.DoubleparseToNumber(java.lang.String text)Parses a given string to aDoubleif possible and returns it.static java.lang.StringreplaceAllSubStrings(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)This method replaces all occurences of asubstringin an original string with a replacement string.static java.lang.StringreplaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)This method replaces the first occurence of a substring in an original string with a replacement string.static java.lang.StringreplaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString, int pos)This method replaces the first occurence of a substring in an original string with a replacement string, starting from a given position.
-
-
-
Field Detail
-
NAN_STRING
public static final java.lang.String NAN_STRING
- See Also:
- Constant Field Values
-
NAN_STRING_ALT
public static final java.lang.String NAN_STRING_ALT
- See Also:
- Constant Field Values
-
POSINF_STRING
public static final java.lang.String POSINF_STRING
- See Also:
- Constant Field Values
-
SIGPOSINF_STRING
public static final java.lang.String SIGPOSINF_STRING
- See Also:
- Constant Field Values
-
NEGINF_STRING
public static final java.lang.String NEGINF_STRING
- See Also:
- Constant Field Values
-
-
Method Detail
-
formatNumber
public static java.lang.String formatNumber(double number, java.text.NumberFormat format, int precision)Formatsnumberwithformatifformat != null. Otherwise returnnumberas a string. The formatter respects the givenprecision.- Parameters:
number- thedoubleto formatformat- the formatter, can benullprecision- number of digits right to the decimal point- Returns:
- a formatted string with
number
-
parseToNumber
public static java.lang.Double parseToNumber(java.lang.String text)
Parses a given string to aDoubleif possible and returns it.NaN, (+)Infinity, and -Infinity,are recognized. If the given string is empty,NaNis returned.- Parameters:
text- a string that should represent a number, scientific notation is recognized as well- Returns:
- the assembled
Doubleornullif something went wrong - Throws:
java.lang.IllegalArgumentException-if (text == null)
-
replaceAllSubStrings
public static java.lang.String replaceAllSubStrings(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)This method replaces all occurences of asubstringin an original string with a replacement string. It does not work with regular expressions.- Parameters:
origString- the string to work onsubstring- must occur completely inorigStringfor the replacement to workreplacementString- the string with whichsubstringis replaced- Returns:
- a new string with the replacement(s) or
origStringif any of the parameters isnull, ifsubstringis empty or ifsubstringdoes not occur inorigString
-
replaceSubString
public static java.lang.String replaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString)This method replaces the first occurence of a substring in an original string with a replacement string. It does not work with regular expressions.- Parameters:
origString- the string to work onsubstring- must occur completely inorigStringfor the replacement to workreplacementString- the string with whichsubstringis replaced- Returns:
- a new string with the replacement or
origStringif any of the parameters isnull, ifsubstringis empty or ifsubstringdoes not occur inorigString
-
replaceSubString
public static java.lang.String replaceSubString(java.lang.String origString, java.lang.String substring, java.lang.String replacementString, int pos)This method replaces the first occurence of a substring in an original string with a replacement string, starting from a given position. It does not work with regular expressions.- Parameters:
origString- the string to work onsubstring- must occur completely inorigStringfor the replacement to workreplacementString- the string with whichsubstringis replacedpos- the index inorigStringto start searching forsubstring, if < 0posis set to 0- Returns:
- a new string with the replacement or
origStringif any of the parameters isnull, ifsubstringis empty or ifsubstringdoes not occur inorigStringor ifpos >= origString.length()
-
capitalizeFirst
public static java.lang.String capitalizeFirst(java.lang.String s)
Resturns string with first characted capitalized, rest lowercase. Useful for names.- Parameters:
s-- Returns:
- string with first char upper case, rest lowercase or
nullifs == null
-
-
DMelt 3.0 © DataMelt by jWork.ORG