Package de.mhus.lib.core
Class MString
- java.lang.Object
-
- de.mhus.lib.core.MString
-
public class MString extends Object
- Author:
- hummel
-
-
Field Summary
Fields Modifier and Type Field Description static Map<String,String>ASCII127_MAPPINGstatic char[]CHARS_READABLEstatic CharsetCHARSET_CHARSET_ISO_8859_1static CharsetCHARSET_CHARSET_UTF_16static CharsetCHARSET_CHARSET_UTF_8static StringCHARSET_DEFAULTstatic StringCHARSET_ISO_8859_1static StringCHARSET_UTF_16static StringCHARSET_UTF_8static StringDEFAULT_SEPARATORstatic String[]EMPTY_PAIRA pair (index 0 and 1) with empty stringsstatic String[]NULL_PAIRA pair (index 0 and 1) with null valuesstatic char[]WHITESPACE
-
Constructor Summary
Constructors Constructor Description MString()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static StringafterIndex(String _s, char _c)Return the string after _c in _s.static StringafterIndex(String _s, char[] _c)Return the string after _c in _s.static StringafterIndex(String _s, char[] _c, String _def)Return the string after _c in _s.static StringafterIndex(String _s, char _c, String _def)Return the string after _c in _s.static StringafterIndex(String _s, String _c)Return the string after _c in _s.static StringafterIndex(String _s, String _c, String _def)Return the string after _c in _s.static StringafterLastIndex(String string, char c)Return the part after the last occurrence of the char.static StringafterLastIndex(String string, char c, String def)Return the part after the last occurrence of the char.static StringafterLastIndex(String string, String c)Return the part after the last occurrence of the char.static StringafterLastIndex(String string, String c, String def)Return the part after the last occurrence of the char.static voidappendRepeating(int amount, char fill, StringBuilder buffer)Append the number of times a character to a string buffer.static StringbeforeIndex(String _s, char _c)Return the string before _c in _s.static StringbeforeIndex(String _s, char[] _c)Return the string before _c in _s.static StringbeforeIndex(String _s, char[] _c, String _def)Return the string before _c in _s.static StringbeforeIndex(String _s, char _c, String _def)Return the string before _c in _s.static StringbeforeIndex(String _s, String _c)Return the string before _c in _s.static StringbeforeIndex(String _s, String _c, String _def)Return the string before _c in _s.static StringbeforeIndexOrAll(String _s, char _c)static StringbeforeLastIndex(String string, char c)Return part before last occurrence of the char.static StringbeforeLastIndex(String string, char c, String def)Return part before last occurrence of the char.static StringbeforeLastIndex(String string, String c)Return part before last occurrence of the char.static StringbeforeLastIndex(String string, String c, String def)Return part before last occurrence of the char.static StringbyteToString(byte[] data)Return a utf-8 decoded string from the data ignoring the VM default char set.static Stringcanonical(String s)Convert String to canonical standard form.static StringcolorToString(Color c)Get #ffffff html hex number for a colourstatic booleancompareFsLikePattern(String str, String pattern)Use * at the beginning or/and the end and a ! at the beginning for 'not'.static booleancompareRegexPattern(String str, String pattern)static booleancompareSQLLikePattern(String str, String pattern)Use % at the beginning and/or the end example: %aloa% or !%aloa%static StringcompileAndExecute(String template, IProperties attributes)static StringcompileAndExecute(String template, IProperties attributes, String def)static Stringcondense(String s)Collapse multiple spaces in string down to a single space.static intcountCharacters(String in, char c)Return the count of the character in the string.static intcountCharacters(String in, char[] c)Return the count of the characters in the string.static intcountLeading(String text, char c)count of how many leading characters there are on a string matching a given character.static intcountTrailing(String text, char c)count of how many trailing characters there are on a string matching a given character.static StringcutAfter(String in, String pattern, char fill, int size)Search for a pattern and cut the string after size characters.static StringdecodeCSV(String _field)static StringdecodeUnicode(String _in)static StringdecodeURIComponent(String _in)static StringencodeCSV(String _field)static StringencodeCSVLine(String[] _fields)static StringencodeUnicode(String _in)static StringencodeUnicode(String _in, boolean encodeCr)static StringencodeURIComponent(String _in)static StringencodeWebUnicode(String _in)Encodes for the web.static booleanequals(String in1, String in2)static StringfindInitials(String title, boolean upperOnly, boolean digits, int maxSize)Try to find initials out of the given title.static StringgetPart(String value, int nr)static StringgetPart(String value, int nr, String def)Split the string in n parts and return the part number nr.static StringgetPart(String value, String separator, int nr)static StringgetPart(String value, String separator, int nr, String def)static StringgetRepeating(int amount, char fill)Repeat the character a given times.static int[]getSelectedPart(String text, int caretPosition)Search in a string the selected paragraph indicated be empty lines.static int[]getSelectedPart(String text, int caretPosition, String[] separators)static StringgetSelection(String text, int[] part, String def)Returns the string part of the selected part.static intindexOf(String _s, char[] _c)Returns the position where the first of one of the chars is found in the string.static intindexOf(String _s, char[] _c, int offset)Returns the position where the first of one of the chars is found in the string.static StringintegerPart(String in)static booleanisComposedOf(String in, String composed)Check a string against all characters in another string.static booleanisEmpty(String _in)Returns true if the string is null or an empty string.static booleanisEmptyTrim(String s)Is this string empty?static booleanisIndex(String _s, char _c)Return, if the char is located in the string (indexOf).static booleanisIndex(String _s, char[] _c)Returns true if one of the chars is found in the string.static booleanisIndex(String _s, String _c)Return, if the char is located in the string (indexOf).static booleanisLegal(String candidate, String legalChars)Ensure the string contains only legal charactersstatic booleanisSet(String _in)Return true if the the string is not empty.static booleanisSetTrim(String _in)Return true if the the string is not empty also trimmed.static booleanisUnaccentedLowerCase(char c)Check if char is plain ASCII lower case.static booleanisUnaccentedUpperCase(char c)Check if char is plain ASCII upper case.static booleanisUnicode(String _in, char _joker, boolean encodeCr)static booleanisWhitespace(char c)Return true if the character is in the list of whitespace.static Stringjoin(long[] src, char glue)static Stringjoin(String[] src, char glue)static Stringjoin(String[] src, int from, int to, String glue)static Stringjoin(Iterator<?> src, String glue)static Stringjoin(List<?> src, String glue)static StringleftPad(String s, int newLen, boolean chop)Pads the string out to the given length by applying blanks on the left.static longparseDirtyLong(String numStr)convert a String to a long.static longparseLongPennies(String numStr)convert a String into long pennies.static StringpenniesToString(long pennies)Print dollar currency, stored internally as scaled int.static StringregexEncode(String in)Deprecated.static Stringrep(char c, int count)Produce a String of a given repeating character.static voidreplaceAll(StringBuilder _src, String _pattern, String _replacement)Replace all pattern thru replacement strings.static StringreplaceAll(String _src, String _pattern, String _replacement)Replace all pattern thru replacement strings.static StringreplaceSelection(String text, int[] part, String replacement)Replace a text in another text.static StringreplaceSQLLikePattern(String str, String pattern, String replace)static StringrightPad(String s, int newLen, boolean chop)Pads the string out to the given length by applying blanks on the right.static Throwableserialize(StringBuilder sb, Object[] msg, int maxMsgSize)static Throwableserialize(StringBuilder sb, Object o, Throwable error)static String[]split(String in, int length)Split string into parts after length is reached.static String[]split(String _in, String _pattern)Split the string in parts.static Collection<String>splitCollection(String in, int length)Split string into parts after length is reached.static String[]splitIgnoreEmpty(String _in, String _pattern)Split the string in parts.static String[]splitIgnoreEmpty(String _in, String _pattern, boolean trim)static String[]splitIndex(String _s, char[] _c, String[] _def)Return the string before _c in _s.static String[]splitIndex(String _s, char _c, String[] _def)Return the string before and after _c in _s.static String[]splitIndex(String _s, String _c, String[] _def)Return the string before and after _c in _s.static String[]splitLastIndex(String string, char c, String[] def)Return part before last occurrence of the char.static String[]splitLastIndex(String string, String c, String[] def)Return part before last occurrence of the char.static Stringsquish(String s)Remove all spaces from a String.static StringtoAscii127(char c)static StringtoAscii127(String in)static StringtoBookTitleCase(String s)convert to Book Title case, with first letter of each word capitalised.static StringtoByteDisplayString(long bytes)static byte[]toBytes(String data)Return a utf-8 encoded byte array from data ignoring the VM default data set.static StringtoHexDump(byte[] bc, int lineSize)static StringtoHexString(int h)Convert int to hex with lead zeroesstatic StringtoLZ(int i, int len)Convert an integer to a String, with left zeroes.static StringtoString(Object val)Convert a object to string using deep stringify mechanisms.static StringtoStringOrNull(Object val)Like toString but if the value is null the return is null.static StringtrimLeading(String s)Removes white space from beginning this string.static StringtrimTrailing(String s)Removes white space from end this string.static Stringtruncate(String in, int length)This will truncate the string at the end.static StringtruncateNice(String in, int length)This will truncate the string, but it also adds three dots (...) at the removed position.static StringtruncateNiceLeft(String in, int length)static Stringwrap(String in, int length)
-
-
-
Field Detail
-
CHARSET_UTF_8
public static final String CHARSET_UTF_8
- See Also:
- Constant Field Values
-
CHARSET_UTF_16
public static final String CHARSET_UTF_16
- See Also:
- Constant Field Values
-
CHARSET_ISO_8859_1
public static final String CHARSET_ISO_8859_1
- See Also:
- Constant Field Values
-
CHARSET_CHARSET_UTF_8
public static final Charset CHARSET_CHARSET_UTF_8
-
CHARSET_CHARSET_UTF_16
public static final Charset CHARSET_CHARSET_UTF_16
-
CHARSET_CHARSET_ISO_8859_1
public static final Charset CHARSET_CHARSET_ISO_8859_1
-
WHITESPACE
public static final char[] WHITESPACE
-
DEFAULT_SEPARATOR
public static final String DEFAULT_SEPARATOR
- See Also:
- Constant Field Values
-
CHARSET_DEFAULT
public static final String CHARSET_DEFAULT
- See Also:
- Constant Field Values
-
CHARS_READABLE
public static final char[] CHARS_READABLE
-
EMPTY_PAIR
public static final String[] EMPTY_PAIR
A pair (index 0 and 1) with empty strings
-
NULL_PAIR
public static final String[] NULL_PAIR
A pair (index 0 and 1) with null values
-
-
Method Detail
-
isSetTrim
public static boolean isSetTrim(String _in)
Return true if the the string is not empty also trimmed.- Parameters:
_in- The string to test- Returns:
- true if the string is not null and not an empty string and not only contains whitespaces
-
isSet
public static boolean isSet(String _in)
Return true if the the string is not empty.- Parameters:
_in- The string to test- Returns:
- true if the string is not null and not an empty string
-
isEmpty
public static boolean isEmpty(String _in)
Returns true if the string is null or an empty string.- Parameters:
_in-- Returns:
- true if empty
-
split
public static String[] split(String _in, String _pattern)
Split the string in parts. Separator is a pattern. In difference of the build in split it will not remove empty parts and the pattern is not a regex.- Parameters:
_in-_pattern-- Returns:
- parts
-
splitIgnoreEmpty
public static String[] splitIgnoreEmpty(String _in, String _pattern)
Split the string in parts. Separator is a pattern. In difference of the build in the pattern is not a regex.- Parameters:
_in-_pattern-- Returns:
- parts
-
splitIgnoreEmpty
public static String[] splitIgnoreEmpty(String _in, String _pattern, boolean trim)
-
replaceAll
public static String replaceAll(String _src, String _pattern, String _replacement)
Replace all pattern thru replacement strings. Pattern is not a regex.- Parameters:
_src-_pattern-_replacement-- Returns:
- new string
-
replaceAll
public static void replaceAll(StringBuilder _src, String _pattern, String _replacement)
Replace all pattern thru replacement strings. Pattern is not a regex.- Parameters:
_src-_pattern-_replacement-
-
isIndex
public static boolean isIndex(String _s, String _c)
Return, if the char is located in the string (indexOf). If _s is null, return is false.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- true if index was found
-
beforeIndex
public static String beforeIndex(String _s, String _c)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part before the index
-
afterIndex
public static String afterIndex(String _s, String _c)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part after the index
-
isIndex
public static boolean isIndex(String _s, char _c)
Return, if the char is located in the string (indexOf). If _s is null, return is false.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- true if the index was found
-
beforeIndex
public static String beforeIndex(String _s, char _c)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part before the index
-
afterIndex
public static String afterIndex(String _s, char _c)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part after the index
-
isIndex
public static boolean isIndex(String _s, char[] _c)
Returns true if one of the chars is found in the string. If _s is null, return is false.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- true if one of the character was found
-
beforeIndex
public static String beforeIndex(String _s, char[] _c)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part before the first found character
-
afterIndex
public static String afterIndex(String _s, char[] _c)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- part after the first found character
-
indexOf
public static int indexOf(String _s, char[] _c, int offset)
Returns the position where the first of one of the chars is found in the string. If _s is null, return is -1.- Parameters:
_s- The string to search in_c- The delimiteroffset-- Returns:
- position of the first found character
-
indexOf
public static int indexOf(String _s, char[] _c)
Returns the position where the first of one of the chars is found in the string.- Parameters:
_s- The string to search in_c- The delimiter- Returns:
- position of the first found character
-
beforeLastIndex
public static String beforeLastIndex(String string, char c)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-- Returns:
- string before the last found character
-
afterLastIndex
public static String afterLastIndex(String string, char c)
Return the part after the last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-- Returns:
- part after last found character
-
beforeLastIndex
public static String beforeLastIndex(String string, String c)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-- Returns:
- part before last found character
-
afterLastIndex
public static String afterLastIndex(String string, String c)
Return the part after the last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-- Returns:
- part after last found character
-
beforeIndex
public static String beforeIndex(String _s, String _c, String _def)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part before the index
-
afterIndex
public static String afterIndex(String _s, String _c, String _def)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part after the index
-
beforeIndex
public static String beforeIndex(String _s, char _c, String _def)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part before the index
-
afterIndex
public static String afterIndex(String _s, char _c, String _def)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part after the index
-
beforeIndex
public static String beforeIndex(String _s, char[] _c, String _def)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part before the first found character
-
afterIndex
public static String afterIndex(String _s, char[] _c, String _def)
Return the string after _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part after the first found character
-
beforeLastIndex
public static String beforeLastIndex(String string, char c, String def)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- string before the last found character
-
afterLastIndex
public static String afterLastIndex(String string, char c, String def)
Return the part after the last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- part after last found character
-
beforeLastIndex
public static String beforeLastIndex(String string, String c, String def)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- part before last found character
-
afterLastIndex
public static String afterLastIndex(String string, String c, String def)
Return the part after the last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- part after last found character
-
splitIndex
public static String[] splitIndex(String _s, String _c, String[] _def)
Return the string before and after _c in _s. If _c is not found in _s, or _s is null then return is _def.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- 0: part before the index, 1: part after the index
-
splitIndex
public static String[] splitIndex(String _s, char _c, String[] _def)
Return the string before and after _c in _s. If _c is not found in _s, or _s is null then return is _def.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- 0: part before the index, 1: part after the index
-
splitIndex
public static String[] splitIndex(String _s, char[] _c, String[] _def)
Return the string before _c in _s. If _c is not found in _s, return is an empty string. If _s is null, return is null.- Parameters:
_s- The string to search in_c- The delimiter_def- Default value, if _s is null or _c not found- Returns:
- part before the first found character
-
splitLastIndex
public static String[] splitLastIndex(String string, char c, String[] def)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- string before the last found character
-
splitLastIndex
public static String[] splitLastIndex(String string, String c, String[] def)
Return part before last occurrence of the char. If the char is not found it will return the hole string.- Parameters:
string-c-def- Default value, if _s is null or _c not found- Returns:
- part before last found character
-
encodeWebUnicode
public static String encodeWebUnicode(String _in)
Encodes for the web. Same like MXml.encode- Parameters:
_in-- Returns:
- encoded string
-
isUnicode
public static boolean isUnicode(String _in, char _joker, boolean encodeCr)
-
compareSQLLikePattern
public static boolean compareSQLLikePattern(String str, String pattern)
Use % at the beginning and/or the end example: %aloa% or !%aloa%- Parameters:
str-pattern-- Returns:
- true if match
-
compareFsLikePattern
public static boolean compareFsLikePattern(String str, String pattern)
Use * at the beginning or/and the end and a ! at the beginning for 'not'. e.g. *aloa* !*aloa*- Parameters:
str-pattern-- Returns:
- true if match
-
replaceSQLLikePattern
public static String replaceSQLLikePattern(String str, String pattern, String replace)
-
join
public static String join(long[] src, char glue)
-
canonical
public static String canonical(String s)
Convert String to canonical standard form. null -> "". Trims lead trail blanks.- Parameters:
s- String to be converted.- Returns:
- String in canonical form.
-
condense
public static String condense(String s)
Collapse multiple spaces in string down to a single space. Remove lead and trailing spaces.- Parameters:
s- String to strip of blanks.- Returns:
- String with all blanks, lead/trail/embedded removed.
-
countLeading
public static int countLeading(String text, char c)
count of how many leading characters there are on a string matching a given character. It does not remove them.- Parameters:
text- text with possible leading characters, possibly empty, but not null.c- the leading character of interest, usually ' ' or '\n'- Returns:
- count of leading matching characters, possibly 0.
-
countTrailing
public static int countTrailing(String text, char c)
count of how many trailing characters there are on a string matching a given character. It does not remove them.- Parameters:
text- text with possible trailing characters, possibly empty, but not null.c- the trailing character of interest, usually ' ' or '\n'- Returns:
- count of trailing matching characters, possibly 0.
-
isEmptyTrim
public static boolean isEmptyTrim(String s)
Is this string empty?- Parameters:
s- String to be tested for emptiness.- Returns:
- true if the string is null or equal to the "" null string. or just blanks
-
isLegal
public static boolean isLegal(String candidate, String legalChars)
Ensure the string contains only legal characters- Parameters:
candidate- string to test.legalChars- characters than are legal for candidate.- Returns:
- true if candidate is formed only of chars from the legal set.
-
isUnaccentedLowerCase
public static boolean isUnaccentedLowerCase(char c)
Check if char is plain ASCII lower case.- Parameters:
c- char to check- Returns:
- true if char is in range a..z
- See Also:
Character.isLowerCase(char)
-
isUnaccentedUpperCase
public static boolean isUnaccentedUpperCase(char c)
Check if char is plain ASCII upper case.- Parameters:
c- char to check.- Returns:
- true if char is in range A..Z.
- See Also:
Character.isUpperCase(char)
-
leftPad
public static String leftPad(String s, int newLen, boolean chop)
Pads the string out to the given length by applying blanks on the left.- Parameters:
s- String to be padded/chopped.newLen- length of new String desired.chop- true if Strings longer than newLen should be truncated to newLen chars.- Returns:
- String padded on left/chopped to the desired length.
-
parseDirtyLong
public static long parseDirtyLong(String numStr)
convert a String to a long. The routine is very forgiving. It ignores invalid chars, lead trail, embedded spaces, decimal points etc. Dash is treated as a minus sign.- Parameters:
numStr- String to be parsed.- Returns:
- long value of String with junk characters stripped.
- Throws:
NumberFormatException- if the number is too big to fit in a long.
-
parseLongPennies
public static long parseLongPennies(String numStr)
convert a String into long pennies. It ignores invalid chars, lead trail, embedded spaces. Dash is treated as a minus sign. 0 or 2 decimal places are permitted.- Parameters:
numStr- String to be parsed.- Returns:
- long pennies.
- Throws:
NumberFormatException- if the number is too big to fit in a long.
-
penniesToString
public static String penniesToString(long pennies)
Print dollar currency, stored internally as scaled int. convert pennies to a string with a decorative decimal point.- Parameters:
pennies- long amount in pennies.- Returns:
- amount with decorative decimal point, but no lead $.
-
rep
public static String rep(char c, int count)
Produce a String of a given repeating character.- Parameters:
c- the character to repeatcount- the number of times to repeat- Returns:
- String, e.g. rep('*',4) returns "****"
-
rightPad
public static String rightPad(String s, int newLen, boolean chop)
Pads the string out to the given length by applying blanks on the right.- Parameters:
s- String to be padded/chopped.newLen- length of new String desired.chop- true if Strings longer than newLen should be truncated to newLen chars.- Returns:
- String padded on left/chopped to the desired length.
-
squish
public static String squish(String s)
Remove all spaces from a String.- Parameters:
s- String to strip of blanks.- Returns:
- String with all blanks, lead/trail/embedded removed.
-
toBookTitleCase
public static String toBookTitleCase(String s)
convert to Book Title case, with first letter of each word capitalised. e.g. "handbook to HIGHER consciousness" -> "Handbook to Higher Consciousness" e.g. "THE HISTORY OF THE U.S.A." -> "The History of the U.S.A." e.g. "THE HISTORY OF THE USA" -> "The History of the Usa" (sorry about that.) Don't confuse this with Character.isTitleCase which concerns ligatures.- Parameters:
s- String to convert. May be any mixture of case.- Returns:
- String with each word capitalised, except embedded words "the" "of" "to"
-
toHexString
public static String toHexString(int h)
Convert int to hex with lead zeroes- Parameters:
h- number you want to convert to hex- Returns:
- 0x followed by unsigned hex 8-digit representation
-
toLZ
public static String toLZ(int i, int len)
Convert an integer to a String, with left zeroes.- Parameters:
i- the integer to be convertedlen- the length of the resulting string. Warning. It will chop the result on the left if it is too long.- Returns:
- String representation of the int e.g. 007
-
colorToString
public static String colorToString(Color c)
Get #ffffff html hex number for a colour- Parameters:
c- Color object whose html colour number you want as a string- Returns:
- # followed by 6 hex digits
- See Also:
toHexString(int)
-
trimLeading
public static String trimLeading(String s)
Removes white space from beginning this string. All characters that have codes less than or equal to'\u0020'(the space character) are considered to be white space.- Parameters:
s- String to process. As always the original in unchanged.- Returns:
- this string, with leading white space removed
-
trimTrailing
public static String trimTrailing(String s)
Removes white space from end this string. All characters that have codes less than or equal to'\u0020'(the space character) are considered to be white space.- Parameters:
s- String to process. As always the original in unchanged.- Returns:
- this string, with trailing white space removed
-
getPart
public static String getPart(String value, int nr, String def)
Split the string in n parts and return the part number nr. If the part is not found the default value will be returned.- Parameters:
value-nr-def-- Returns:
- the part
-
truncate
public static String truncate(String in, int length)
This will truncate the string at the end. If the string is shorter as length it returns the string itself.- Parameters:
in- String to truncatelength- Max length of the string- Returns:
- truncated string
-
truncateNice
public static String truncateNice(String in, int length)
This will truncate the string, but it also adds three dots (...) at the removed position. The truncation is not at the end at all. The resulted string is a nice representation of the original input. Use this function to display a truncated string. abc...xyz- Parameters:
in- String to truncatelength- Max length of the string- Returns:
- truncated string
-
getSelectedPart
public static int[] getSelectedPart(String text, int caretPosition)
Search in a string the selected paragraph indicated be empty lines. If the caret position outside the string it will return null.- Parameters:
text- The string, must not be nullcaretPosition- Position of the caret.- Returns:
- the position or null if the input string is null. Return is int[] {start, end}
-
getSelectedPart
public static int[] getSelectedPart(String text, int caretPosition, String[] separators)
-
getSelection
public static String getSelection(String text, int[] part, String def)
Returns the string part of the selected part. If the part position is outside the bounds of the string it will be trimmed. If the part position is not correct or the returned string is empty then the default string is returned. Good values for the default are null or an empty string. Use this method with the result of getSelectedPart()- Parameters:
text- The text to croppart- The position in the text, first element is the begin second element the end of the selection.def- Return this if a selection is not possible.- Returns:
- The selected part of the text.
-
replaceSelection
public static String replaceSelection(String text, int[] part, String replacement)
Replace a text in another text.- Parameters:
text-part-replacement-- Returns:
- new String
-
appendRepeating
public static void appendRepeating(int amount, char fill, StringBuilder buffer)Append the number of times a character to a string buffer.- Parameters:
amount- number of repeatingsfill- char to fillbuffer- target
-
getRepeating
public static String getRepeating(int amount, char fill)
Repeat the character a given times.- Parameters:
amount- number of repeatingfill- char to fill- Returns:
- string n times the character
-
isWhitespace
public static boolean isWhitespace(char c)
Return true if the character is in the list of whitespace.- Parameters:
c-- Returns:
- true if character is defined as whitespace
-
countCharacters
public static int countCharacters(String in, char c)
Return the count of the character in the string.- Parameters:
in-c-- Returns:
- count of chars or 0 if 'in' is null
-
countCharacters
public static int countCharacters(String in, char[] c)
Return the count of the characters in the string.- Parameters:
in-c-- Returns:
- count of chars or 0 if 'in' is null
-
findInitials
public static String findInitials(String title, boolean upperOnly, boolean digits, int maxSize)
Try to find initials out of the given title. Use the first letters after whitspaces for the initials. The returned string is not in upper letters. If you need Upper Letters append toUpper().- Parameters:
title- The input StringupperOnly- Set true if only collect upper characters in titledigits- Set true if digits (after whitespaces) should also be used.maxSize- Max size in characters of the initilas or 0 for no limit.- Returns:
- The initials in mixed letters.
-
isComposedOf
public static boolean isComposedOf(String in, String composed)
Check a string against all characters in another string. If the first string is not build from characters of the other one the method returns false.- Parameters:
in-composed-- Returns:
- true if composed
-
toByteDisplayString
public static String toByteDisplayString(long bytes)
-
regexEncode
@Deprecated public static String regexEncode(String in)
Deprecated.Encode a string to be used in an regular expression. Use Pattern.quote instead !- Parameters:
in- String- Returns:
- Encoded String
-
toHexDump
public static String toHexDump(byte[] bc, int lineSize)
-
toBytes
public static byte[] toBytes(String data)
Return a utf-8 encoded byte array from data ignoring the VM default data set.- Parameters:
data-- Returns:
- utf-8 encoded byte array
-
byteToString
public static String byteToString(byte[] data)
Return a utf-8 decoded string from the data ignoring the VM default char set.- Parameters:
data-- Returns:
- utf-8 decoded string
-
split
public static String[] split(String in, int length)
Split string into parts after length is reached.- Parameters:
in-length-- Returns:
- the spit string into an array
-
splitCollection
public static Collection<String> splitCollection(String in, int length)
Split string into parts after length is reached.- Parameters:
in-length-- Returns:
- the split string into a collection
-
toString
public static String toString(Object val)
Convert a object to string using deep stringify mechanisms. Will never return null, instead of null the string '[null]' will be returned.- Parameters:
val-- Returns:
- The object as string
-
toStringOrNull
public static String toStringOrNull(Object val)
Like toString but if the value is null the return is null.- Parameters:
val-- Returns:
- The object as string or null
-
serialize
public static Throwable serialize(StringBuilder sb, Object o, Throwable error)
-
serialize
public static Throwable serialize(StringBuilder sb, Object[] msg, int maxMsgSize)
-
compileAndExecute
public static String compileAndExecute(String template, IProperties attributes) throws de.mhus.lib.errors.MException
- Throws:
de.mhus.lib.errors.MException
-
compileAndExecute
public static String compileAndExecute(String template, IProperties attributes, String def)
-
cutAfter
public static String cutAfter(String in, String pattern, char fill, int size)
Search for a pattern and cut the string after size characters. If the string is too short it will be filled with fill characters.- Parameters:
in- The string to cutpattern- The pattern to search for (not regex!)fill- Fill character or 0 to disablesize- size after (or negative before) the found pattern- Returns:
- The cutted string
-
toAscii127
public static String toAscii127(char c)
-
-